コード例 #1
0
ファイル: sync_execute.py プロジェクト: DimaJedi/my-selling
	def run(self):


		self.con=sql.connect('app/db/main.db')
		self.con.create_function('myDate',2,lambda x,y:date2int(x,y))
		self.db=self.con.cursor()

		# если синхронизация не нужна, выходим
		self.db.execute('select value from misc where name="sync_enable"')
		if not self.db.fetchall()[0][0]=='1':return
		# если синхронизация только при выходе из приложения, выходим...
		self.db.execute('select value from misc where name="sync_period"')
		sync_time=int(self.db.fetchall()[0][0])
		if sync_time==0:return
	
		
		self.db.execute('select value from misc where name="sync_point"')
		self.sync_point=self.db.fetchall()[0][0].encode('utf-8')


		self.sync_point=hash(self.sync_point)
		
		self.db.execute('select value from misc where name="sync_login"')
		self.sync_login=self.db.fetchall()[0][0]

		self.db.execute('select value from misc where name="sync_passw"')
		self.sync_passw=self.db.fetchall()[0][0]
		
		self.db.execute('select value from misc where name="sync_server"')
		self.sync_server=self.db.fetchall()[0][0]

		while 1:
			time.sleep(sync_time*60)
			try:self.sync()
			except Exception:pass
コード例 #2
0
    def run(self):

        self.con = sql.connect('app/db/main.db')
        self.con.create_function('myDate', 2, lambda x, y: date2int(x, y))
        self.db = self.con.cursor()

        # если синхронизация не нужна, выходим
        self.db.execute('select value from misc where name="sync_enable"')
        if not self.db.fetchall()[0][0] == '1': return
        # если синхронизация только при выходе из приложения, выходим...
        self.db.execute('select value from misc where name="sync_period"')
        sync_time = int(self.db.fetchall()[0][0])
        if sync_time == 0: return

        self.db.execute('select value from misc where name="sync_point"')
        self.sync_point = self.db.fetchall()[0][0].encode('utf-8')

        self.sync_point = hash(self.sync_point)

        self.db.execute('select value from misc where name="sync_login"')
        self.sync_login = self.db.fetchall()[0][0]

        self.db.execute('select value from misc where name="sync_passw"')
        self.sync_passw = self.db.fetchall()[0][0]

        self.db.execute('select value from misc where name="sync_server"')
        self.sync_server = self.db.fetchall()[0][0]

        while 1:
            time.sleep(sync_time * 60)
            try:
                self.sync()
            except Exception:
                pass
コード例 #3
0
ファイル: main.py プロジェクト: DimaJedi/my-selling
	def __init__(self,root):
		self.version=version
		self.is_exit=False
		self.title='%s - '+self.version
		root.title(self.title%('Выбор пользователя'))
		
		if sys.platform=='win32':
			root.state('zoomed')
			root.iconbitmap('app/images/icon.ico')		
		
		self.root=root
		self.root.protocol("WM_DELETE_WINDOW", self.exit)




		self.con=sql.connect('app/db/main.db')
		self.db=self.con.cursor()
		
		try:
			self.db.execute('select name from dep')
		except sql.OperationalError:
			# если базы данных нет, то создаем ее из схемы
			self.db.executescript(open('app/db/schema.sql').read())
		# функция для поиска по юникоду в базе данных
		self.con.create_function('myLower',1,lambda x:x.lower())
		# для поиска по "больше чем дата и время"
		self.con.create_function('myDate',2,lambda x,y:date2int(x,y))
		self.sets=settings.Settings(self)



		self.create_images()
		self.win=Frame(self.root)
		self.win.pack(expand=YES,fill=BOTH)

		# провереряем, есть ли сохраненные апдейты,если есть, апдейтимся
		upd=os.listdir('app/updates')
		if len(upd)>0:
			s=updates.Main(self)
		else:
			self.change_user()
		# запускаем execute  плагины
		s=os.listdir('app/plugins/execute')
		self.t_pl={}
		for n,x in enumerate(s):
			if x.endswith('.py'):
				obj=__import__(x[:-3])
				self.t_pl[n]=getattr (obj, 'Plugin')(self)	

				pass
コード例 #4
0
ファイル: sync_execute.py プロジェクト: DimaJedi/my-selling
	def sync(self):

		self.db.execute('select value from misc where name="update_date"')
		update_date=self.db.fetchall()[0][0]
		self.db.execute('select value from misc where name="update_time"')
		update_time=self.db.fetchall()[0][0]


		r={}

		r['auth']={'login':self.sync_login,'passw':self.sync_passw}
		r['db']=self.sync_point
		out=[]
		n_dt=date2int(update_date,update_time)
		self.db.execute('select date,time,dep,article,sum,rate,name from income where myDate(date,time)>=?',(n_dt,))
		for x in self.db.fetchall():
			out.append(['income']+list(x))
			
		self.db.execute('select date,time,article,sum,name from outcome where myDate(date,time)>=?',(n_dt,))
		for x in self.db.fetchall():
			out.append(['outcome']+list(x))
		
		
		self.db.execute('select original_date,original_time,title from edit_log where myDate(date,time)>=?',(n_dt,))
		for x in self.db.fetchall():
			if x[2]==u'Отредактирована продажа':
				self.db.execute('select date,time,dep,article,sum,rate,name from income where date=? and time=?',(x[0],x[1]))
				try:out.append(['income']+list(self.db.fetchall()[0]))
				except IndexError:pass
			elif x[2]==u'Отредактирован расход':
				self.db.execute('select date,time,article,sum,name from outcome where date=? and time=?',(x[0],x[1]))
				try:out.append(['outcome']+list(self.db.fetchall()[0]))
				except IndexError:pass
			if x[2]==u'Удалена продажа':
				out.append(['del_income',x[0],x[1]])
			if x[2]==u'Удален расход':
				out.append(['del_outcome',x[0],x[1]])
		if len(out)==0:

			return
		r['data']=out
		d={}
		d['data']=json.dumps(r)
		self.db.execute('select value from misc where name="sync_server"')
		sync_server=self.db.fetchall()[0][0]
		response=urllib.urlopen(sync_server+'/sync',urllib.urlencode(d)).read()
		if response=='1':
			self.db.execute('update misc set value=? where name="update_date"',(date_now(),))
			self.db.execute('update misc set value=? where name="update_time"',(time_now(),))
			self.con.commit()
コード例 #5
0
    def __init__(self, root):
        self.version = version
        self.is_exit = False
        self.title = '%s - ' + self.version
        root.title(self.title % ('Выбор пользователя'))

        if sys.platform == 'win32':
            root.state('zoomed')
            root.iconbitmap('app/images/icon.ico')

        self.root = root
        self.root.protocol("WM_DELETE_WINDOW", self.exit)

        self.con = sql.connect('app/db/main.db')
        self.db = self.con.cursor()

        try:
            self.db.execute('select name from dep')
        except sql.OperationalError:
            # если базы данных нет, то создаем ее из схемы
            self.db.executescript(open('app/db/schema.sql').read())
        # функция для поиска по юникоду в базе данных
        self.con.create_function('myLower', 1, lambda x: x.lower())
        # для поиска по "больше чем дата и время"
        self.con.create_function('myDate', 2, lambda x, y: date2int(x, y))
        self.sets = settings.Settings(self)

        self.create_images()
        self.win = Frame(self.root)
        self.win.pack(expand=YES, fill=BOTH)

        # провереряем, есть ли сохраненные апдейты,если есть, апдейтимся
        upd = os.listdir('app/updates')
        if len(upd) > 0:
            s = updates.Main(self)
        else:
            self.change_user()
        # запускаем execute  плагины
        s = os.listdir('app/plugins/execute')
        self.t_pl = {}
        for n, x in enumerate(s):
            if x.endswith('.py'):
                obj = __import__(x[:-3])
                self.t_pl[n] = getattr(obj, 'Plugin')(self)

                pass
コード例 #6
0
	def sync(self):	

		self.con=self.app.con
		self.db=self.con.cursor()
		# если не нужно, то выходим
		self.db.execute('select value from misc where name="sync_enable"')
		if self.db.fetchall()[0][0]=='0':

			sys.exit(0)
		

		self.db.execute('select value from misc where name="sync_period"')
		sync_time=int(self.db.fetchall()[0][0])
	
		
		self.db.execute('select value from misc where name="sync_point"')
		self.sync_point=self.db.fetchall()[0][0].encode('utf-8')


		self.sync_point=hash(self.sync_point)
		
		self.db.execute('select value from misc where name="sync_login"')
		self.sync_login=self.db.fetchall()[0][0]

		self.db.execute('select value from misc where name="sync_passw"')
		self.sync_passw=self.db.fetchall()[0][0]
		
		self.db.execute('select value from misc where name="sync_server"')
		self.sync_server=self.db.fetchall()[0][0]
		
		
		self.db.execute('select value from misc where name="update_date"')
		update_date=self.db.fetchall()[0][0]
		self.db.execute('select value from misc where name="update_time"')
		update_time=self.db.fetchall()[0][0]


		r={}

		r['auth']={'login':self.sync_login,'passw':self.sync_passw}
		r['db']=self.sync_point
		out=[]
		n_dt=date2int(update_date,update_time)
		self.db.execute('select date,time,dep,article,sum,rate,name from income where myDate(date,time)>=?',(n_dt,))
		for x in self.db.fetchall():

			out.append(['income']+list(x))
			
		self.db.execute('select date,time,article,sum,name from outcome where myDate(date,time)>=?',(n_dt,))
		for x in self.db.fetchall():
			out.append(['outcome']+list(x))
		
		
		self.db.execute('select original_date,original_time,title from edit_log where myDate(date,time)>=?',(n_dt,))
		for x in self.db.fetchall():
			if x[2]==u'Отредактирована продажа':
				self.db.execute('select date,time,dep,article,sum,rate,name from income where date=? and time=?',(x[0],x[1]))
				try:out.append(['income']+list(self.db.fetchall()[0]))
				except IndexError:pass
			elif x[2]==u'Отредактирован расход':
				self.db.execute('select date,time,article,sum,name from outcome where date=? and time=?',(x[0],x[1]))
				try:out.append(['outcome']+list(self.db.fetchall()[0]))
				except IndexError:pass
			if x[2]==u'Удалена продажа':
				out.append(['del_income',x[0],x[1]])
			if x[2]==u'Удален расход':
				out.append(['del_outcome',x[0],x[1]])
		if len(out)==0:

			sys.exit(0)
		self.lab['text']='Выполняется отправка данных на сервер...'
		self.lab['background']='green'
		self.lab['foreground']='black'
		self.win.update()

		r['data']=out
		d={}
		d['data']=json.dumps(r)
		self.db.execute('select value from misc where name="sync_server"')
		sync_server=self.db.fetchall()[0][0]
		response=urllib.urlopen(sync_server+'/sync',urllib.urlencode(d)).read()
		if response=='1':
			self.db.execute('update misc set value=? where name="update_date"',(date_now(),))
			self.db.execute('update misc set value=? where name="update_time"',(time_now(),))
			self.con.commit()
			sys.exit(0)
		else:
			raise
コード例 #7
0
    def sync(self):

        self.db.execute('select value from misc where name="update_date"')
        update_date = self.db.fetchall()[0][0]
        self.db.execute('select value from misc where name="update_time"')
        update_time = self.db.fetchall()[0][0]

        r = {}

        r['auth'] = {'login': self.sync_login, 'passw': self.sync_passw}
        r['db'] = self.sync_point
        out = []
        n_dt = date2int(update_date, update_time)
        self.db.execute(
            'select date,time,dep,article,sum,rate,name from income where myDate(date,time)>=?',
            (n_dt, ))
        for x in self.db.fetchall():
            out.append(['income'] + list(x))

        self.db.execute(
            'select date,time,article,sum,name from outcome where myDate(date,time)>=?',
            (n_dt, ))
        for x in self.db.fetchall():
            out.append(['outcome'] + list(x))

        self.db.execute(
            'select original_date,original_time,title from edit_log where myDate(date,time)>=?',
            (n_dt, ))
        for x in self.db.fetchall():
            if x[2] == u'Отредактирована продажа':
                self.db.execute(
                    'select date,time,dep,article,sum,rate,name from income where date=? and time=?',
                    (x[0], x[1]))
                try:
                    out.append(['income'] + list(self.db.fetchall()[0]))
                except IndexError:
                    pass
            elif x[2] == u'Отредактирован расход':
                self.db.execute(
                    'select date,time,article,sum,name from outcome where date=? and time=?',
                    (x[0], x[1]))
                try:
                    out.append(['outcome'] + list(self.db.fetchall()[0]))
                except IndexError:
                    pass
            if x[2] == u'Удалена продажа':
                out.append(['del_income', x[0], x[1]])
            if x[2] == u'Удален расход':
                out.append(['del_outcome', x[0], x[1]])
        if len(out) == 0:

            return
        r['data'] = out
        d = {}
        d['data'] = json.dumps(r)
        self.db.execute('select value from misc where name="sync_server"')
        sync_server = self.db.fetchall()[0][0]
        response = urllib.urlopen(sync_server + '/sync',
                                  urllib.urlencode(d)).read()
        if response == '1':
            self.db.execute('update misc set value=? where name="update_date"',
                            (date_now(), ))
            self.db.execute('update misc set value=? where name="update_time"',
                            (time_now(), ))
            self.con.commit()