def get(cls, owner_access_token, uid, count=50, page=1, sort=0): client = client_with_access_token(owner_access_token) r = client.friendships.friends.bilateral.ids.get(uid=uid, count=count, page=page, sort=sort) uids = r.ids return cls(uid, uids)
def user_timeline(owner_access_token, uid, count=3, hrs_limit=48): c = client_with_access_token(owner_access_token) try: r = c.statuses.user_timeline.get(uid=uid, feature=WEIBO_TYPE_VIDEO, count=count) except: return [] # TODO statuses = [s for s in r.statuses if s.created_at] return statuses
def get_long_urls(cls, owner_access_token, urls): """ return dict (short_url -> long_url) """ c = client_with_access_token(owner_access_token) r = None while not r: try: # URLencoded r = c.short_url.expand.get(url_short=urls) except Exception as e: print repr(e) return r.urls
def user_ids(cls, owner_access_token, uid): c = client_with_access_token(owner_access_token) # TODO: cache 考虑持久化 # 目前只能处理200个关注用户里的大V # FIXME: 性能 批量获得 用户关注的用户里面的情况 # r = c.friendships.friends.ids.get(uid=uid, # count=5000) r = c.friendships.friends.get(uid=uid, count=200) follows = r.users bi_uids = Bi.get(owner_access_token, uid, count=2000).uids big_v = rule(follows) return list(set(bi_uids) | big_v)
def big_v_user_ids(cls, owner_access_token, uid): c = client_with_access_token(owner_access_token) # TODO: 待改,用 ids 的,然后跟死列表比较 r = None while not r: try: r = c.friendships.friends.get(uid=uid, count=200) except Exception as e: print repr(e) follows = r.users big_v = rule(follows) return list(big_v)
def user_timeline_batch(owner_access_token, uids, count=3, hrs_limit=48): c = client_with_access_token(owner_access_token) try: r = c.statuses.timeline_batch.get(uids=uids, feature=WEIBO_TYPE_VIDEO, count=count) except Exception as e: print repr(e) return [] # TODO print r return r statuses = [s for s in r.statuses if s.created_at] return statuses
def get(cls, owner_access_token, start=0, limit=3): c = client_with_access_token(owner_access_token) r = None while not r: try: r = c.suggestions.users.may_interested.get( count=100) except Exception as e: print repr(e) uids = [u.uid for u in r[start:limit]] statuses = [t for uid in uids for t in user_timeline(owner_access_token, uid)] make_statuses(owner_access_token, statuses) return statuses
def get(cls, owner_access_token, start=0, limit=3): c = client_with_access_token(owner_access_token) r = None while not r: try: r = c.suggestions.users.may_interested.get(count=100) except Exception as e: print repr(e) uids = [u.uid for u in r[start:limit]] statuses = [ t for uid in uids for t in user_timeline(owner_access_token, uid) ] make_statuses(owner_access_token, statuses) return statuses
def get(cls, owner_uid, owner_access_token, since_id=0, max_id=0, count=20, page=1): client = client_with_access_token(owner_access_token) r = None while not r: try: r = client.statuses.home_timeline.get(feature=WEIBO_TYPE_VIDEO, since_id=since_id, max_id=max_id, count=count, page=page) except Exception as e: print repr(e) make_statuses(owner_access_token, r.statuses) return cls(owner_uid, owner_access_token, r)