def _new_video(self, owner, filepath, sha1): if (not self.user_model._check_user_exist_by_name(owner)): return -2 elif (not self.redis_client.exists(':'.join([self.VIDEO_SHA1, sha1, self.VID]))): vid = str(self.redis_client.incr(self.GLOBAL_VIDEOID_FLAG)) self._init_empty_video_info(vid) self.redis_client.set(':'.join([self.VIDEO_SHA1, sha1, self.VID]), vid) now = gettime.gettime() self.redis_client.set(':'.join([self.VID, vid, self.PUBLIC_TIME]), now.get()) info = {self.VID :vid, self.VIDEO_SHA1 :sha1, self.OWNER :owner, self.PUBLIC_TIME:now.get()} self.redis_client.hmset(':'.join([self.VID, vid, self.HASH]), info) uid = self.user_model._get_user_id(owner) self.redis_client.lpush(':'.join([self.UID, uid, self.VIDEO_LIST]), vid) return vid else: #already in database return -2
import tkinter as tk from time import sleep from gettime import gettime from display import getdisplaytext as display app = tk.Tk() app.title("Binary Timer") x = tk.StringVar() label = tk.Label(app, textvariable=x, font=('Helvetica', 90)) label.pack(side=tk.BOTTOM) while True: x.set(display(gettime())) try: app.update_idletasks() app.update() except Exception as error: if app: exit() sleep(.005)
def _add_comment(self, username, vid, comment): now = gettime.gettime() mcomment = {'reviewer':username, 'content':comment, 'posttime':now.get()} self.redis_client.lpush(':'.join([self.VID, vid, self.COMMENT]), mcomment)
# print elem[PUBLIC_TIME] # print self.redis_client.smembers(':'.join([self.USERNAME, username, SORTEDLIST])) sorted_list = self.redis_client.sort(':'.join([self.USERNAME,username, self.SORTEDLIST]) , \ desc=True, \ by=':'.join([':'.join([self.VID, '*', self.PUBLIC_TIME])])) for elem in self._get_json_video_list(sorted_list)['video_list']: print elem[self.PUBLIC_TIME] return self._get_json_video_list(sorted_list) def get_all_video(self, username): video_list = [] uid = self.user._get_user_id(username) userlist = self.user._get_user_following_list(uid) userlist.add(uid) vid_list = [] for i in userlist: vid_list.extend(self.get_video_list_byuserid(i)) return json.dumps(self._get_json_video_list_sortedbydate(vid_list, username)) def _clear_all(self): for elem in self.redis_client.keys(): self.redis_client.delete(elem) if __name__ == '__main__': now = gettime.gettime() print now.get() tmp = mmodel() #tmp._clear_all() tmp._print_all_user()