Esempio n. 1
0
 def get_noti(self, nid):
     nname = get_noti_hkey(nid)
     ntype = self.r.hget(nname, NOTI_TYPE)
     nread = self.r.hget(nname, NOTI_READ)
     ntime = common.format_datetime(float(self.r.hget(nname, NOTI_TIME)))
     if ntype == FOLLOW_NOTI:
         msg = self.get_username(self.r.hget(nname, NOTI_CREATOR)) + " is following you."
         url = self.r.hget(get_noti_hkey(nid), NOTI_CREATOR)
     else:
         msg = self.get_username(self.r.hget(get_noti_hkey(nid), NOTI_CREATOR)) + " commented on you tweet."
         url = self.r.hget(get_noti_hkey(nid), NOTI_TWEET)
     return {NOTI_ID: nid, NOTI_TYPE: ntype, 'noti_msg': msg, 'noti_target': url, NOTI_TIME: ntime, NOTI_READ: nread}
Esempio n. 2
0
 def get_noti_data(self, nid):
     hkeys = self.r.hkeys(get_noti_hkey(nid))
     noti = {NOTI_ID: nid}
     for k in hkeys:
         val = self.r.hget(get_noti_hkey(nid), k)
         if k == NOTI_TIME:
             noti[k] = common.format_datetime(float(val))
         else:
             noti[k] = unicode(val, "utf8")
         if k == NOTI_CREATOR:
             noti['creator_name'] = self.get_username(val)
     return noti
Esempio n. 3
0
 def get_user_info(self, uid):
     user = {'user_id': uid}
     hkeys = self.r.hkeys(get_user_hkey(uid))
     for k in hkeys:
         val = self.r.hget(get_user_hkey(uid), k)
         if k == USER_JOINED:
             user[k] = common.format_datetime(float(val))
         elif k == USER_IMG:
             user[k] = self.get_userimg(uid)
         else:
             user[k] = unicode(val, "utf8")
     user['followers'] = self.get_followers(uid)
     user['followings'] = self.get_followings(uid)
     return user
Esempio n. 4
0
 def get_comments(self, tweet_id):
     comments = []
     for cmt_id in self.get_comment_ids(tweet_id):
         cmt = {}
         hkeys = self.r.hkeys(get_comment_hkey(cmt_id))
         for k in hkeys:
             val = self.r.hget(get_comment_hkey(cmt_id), k)
             if k == COMMENT_TIME:
                 cmt[k] = common.format_datetime(float(val))
             else:
                 cmt[k] = unicode(val, "utf8")
             if k == COMMENT_USER:
                 cmt[COMMENT_USERNAME] = self.get_username(val)
                 cmt[COMMENT_USERALIAS] = self.get_useralias(val)
         comments.append(cmt)
     return comments
Esempio n. 5
0
 def get_tweet(self, tweet_id):
     tname = get_tweet_hkey(tweet_id)
     hkeys = self.r.hkeys(tname)
     tweet = {'tweet_id': tweet_id}
     for k in hkeys:
         val = self.r.hget(tname, k)
         if k == TWEET_IMG and val:
             if self.config['LOCAL']:
                 tweet[k] = os.path.join('tmp', val)
             else:
                 tweet[k] = self.s3_get(self.config['BUCKET'], val)
         elif k == TWEET_TIME:
             tweet[k] = common.format_datetime(float(val))
         else:
             tweet[k] = unicode(val, "utf8")
         if k == TWEET_USER:
             tweet[USER_NAME] = self.get_username(val)
             tweet[USER_ALIAS] = self.get_useralias(val)
             tweet[USER_IMG] = self.get_userimg(val)
     tweet[COMMENTS] = self.get_comments(tweet_id)
     return tweet