def saveUser(god_name, ins_name, user, sync_key): social_user = public_bz.storage() social_user.type = 'instagram' # social_user.name = user['username'] social_user.name = ins_name social_user.count = user['followed_by']['count'] social_user.avatar = user['profile_pic_url'] social_user.description = user['biography'] social_user.id = user['id'] social_user.sync_key = sync_key pg.update('god', where={'name': god_name}, instagram=json.dumps(social_user)) return social_user
def saveUser(god_name, tumblr_name, user): social_user = public_bz.storage() social_user.type = 'tumblr' # social_user.name = user['name'] social_user.name = tumblr_name social_user.count = user.get('likes', -1) # 有人会不分享likes数 avatar_url = 'https://api.tumblr.com/v2/blog/%s.tumblr.com/avatar/512' % user[ 'name'] social_user.avatar = tumblrRealAvatar(avatar_url) social_user.description = user['description'] social_user.sync_key = user['updated'] pg.update('god', where={'name': god_name}, tumblr=json.dumps(social_user)) return social_user
def saveUser(god_name, twitter_name, twitter_user): social_user = public_bz.storage() # 不要用返回的name, 大小写会发生变化 # social_user.name = twitter_user.screen_name social_user.name = twitter_name social_user.type = 'twitter' social_user.count = twitter_user.followers_count social_user.avatar = twitter_user.profile_image_url_https.replace('_normal', '_400x400') social_user.description = twitter_user.description # 没有找到 # social_user.sync_key = twitter_user.description pg.update('god', where={'name': god_name}, twitter=json.dumps(social_user)) return social_user
def saveUser(god_name, facebook_name, user, etag): social_user = public_bz.storage() social_user.type = 'facebook' # social_user.name = user['username'] social_user.name = facebook_name # facebook 取不到 friend count or followed count social_user.count = -1 social_user.avatar = user['picture']['data']['url'] social_user.description = user.get('bio') # bio 可能没有 if etag is not None: social_user.sync_key = etag social_user.out_id = user['id'] pg.update('god', where={'name': god_name}, facebook=json.dumps(social_user)) return social_user
def saveLast(last_time, user_id): ''' create by bigzhu at 15/08/16 16:22:39 保存最后一条的message ''' id = pg.insertIfNotExist('last', {'user_id': user_id, 'last_time': last_time}, "user_id='%s'" % user_id) if id is None: count = pg.update('last', where="last_time< $last_time and user_id=$user_id", last_time=last_time, vars=locals()) return count return 1
def post(self): ''' modify by bigzhu at 16/04/26 10:48:43 已经存在时不要update modify by bigzhu at 16/06/18 11:36:12 如果是public的,不要update cat modify by bigzhu at 16/06/25 07:48:51 cat = recommand 时, 改为大杂烩 ''' self.set_header("Content-Type", "application/json") user_id = self.current_user data = json.loads(self.request.body) name = data['name'] cat = data.get('cat', '大杂烩') where = {'lower(name)': name.lower()} gods = pg.select('god', where=where) if (gods): god = gods[0] god_id = god.id if god.is_black == 1: raise Exception('%s这是一个黑名名帐号,不添加!' % name) if cat != '大杂烩': pg.update('god', where=where, cat=cat) else: data = { 'name': name, 'cat': cat, 'twitter': god_oper.makeSureSocialUnique('twitter', name), 'github': god_oper.makeSureSocialUnique('github', name), 'instagram': god_oper.makeSureSocialUnique('instagram', name), 'tumblr': god_oper.makeSureSocialUnique('tumblr', name), 'facebook': god_oper.makeSureSocialUnique('facebook', name), 'user_id': user_id } god_id = pg.insert('god', **data) follow_who_oper.follow(user_id, god_id, make_sure=False) god_info = god_oper.getTheGodInfo(god_id, user_id=user_id) self.write( json.dumps({ 'error': '0', 'god_info': god_info }, cls=json_bz.ExtEncoder))
def delNoName(type, god_name): ''' modify by bigzhu at 16/05/27 11:01:43 删除没有的社交 >>> delNoName('instagram', 'bigzhu') del ... 1 ''' values = {type: json.dumps({'name': ''})} count = pg.update('god', where={'name': god_name}, **values) print('del %s %s' % (type, god_name)) return count
def saveUser(god_name, github_name, user, sync_key=None): social_user = public_bz.storage() try: # social_user.name = user['login'] social_user.name = github_name except Exception as e: print e print user social_user.type = 'github' if user.get('followers') is None: social_user.count = -1 else: social_user.count = user['followers'] social_user.avatar = user.get('avatar_url', '') social_user.description = user.get('bio') if sync_key is not None: social_user.sync_key = sync_key pg.update('god', where={'name': god_name}, github=json.dumps(social_user)) return social_user
def getWechat(): ''' 控制最新的wechat ''' result = list(pg.select('wechat_dead_line')) if result: wechat_dead_line = result[0] now = datetime.datetime.now() if wechat_dead_line.access_token_expires_at is not None and now < wechat_dead_line.access_token_expires_at and now < wechat_dead_line.jsapi_ticket_expires_at: wechat = WechatBasic( jsapi_ticket=wechat_dead_line.jsapi_ticket, jsapi_ticket_expires_at=time_bz.datetimeToTimestamp( wechat_dead_line.jsapi_ticket_expires_at), access_token=wechat_dead_line.access_token, access_token_expires_at=time_bz.datetimeToTimestamp( wechat_dead_line.access_token_expires_at), token=token, appid=appid, appsecret=appsecret) else: wechat, access_token, access_token_expires_at, jsapi_ticket, jsapi_ticket_expires_at = getNewWechatInfo( ) pg.update('wechat_dead_line', where='1=1', access_token=access_token, access_token_expires_at=access_token_expires_at, jsapi_ticket=jsapi_ticket, jsapi_ticket_expires_at=jsapi_ticket_expires_at) else: wechat, access_token, access_token_expires_at, jsapi_ticket, jsapi_ticket_expires_at = getNewWechatInfo( ) pg.insert('wechat_dead_line', access_token=access_token, access_token_expires_at=access_token_expires_at, jsapi_ticket=jsapi_ticket, jsapi_ticket_expires_at=jsapi_ticket_expires_at) return wechat
def put(self): self.set_header("Content-Type", "application/json") data = json.loads(self.request.body) name = data['name'] if name == '' or name is None: raise Exception('必须有名字才能修改') for type in ['twitter', 'github', 'instagram', 'tumblr', 'facebook']: god_oper.checkOtherNameSocialNameUnique(name, data[type]['name'], type) data[type] = json.dumps(data[type]) where = " name='%s' " % name count = pg.update("god", where=where, **data) if count != 1: raise Exception("修改失败" + count) self.write( json.dumps({ 'error': '0', 'count': count }, cls=json_bz.ExtEncoder))
def bindUser(user_name, openid): count = pg.update('wechat_user', where="openid='%s'" % openid, user_name=user_name) if count != 1: raise Exception('绑定失败: count=%s, openid=%s' % (count, openid))