Beispiel #1
0
def get_one_page(weibo_id_str: str, page_id: int) -> list or None:
    data = {'containerid': '107603' + weibo_id_str, 'page': page_id}
    r = requests_get(url, data)
    returned_json = r.json()

    if not returned_json['ok']:
        return None

    weibo_cards = returned_json['data']['cards']
    weibo_posts = []
    for weibo_card in weibo_cards:
        if weibo_card['card_type'] != 9:
            continue

        weibo_post_info = weibo_card['mblog']
        # Skips sticky post
        # TODO: return sticky post if it has not been saved
        if weibo_post_info.get('isTop'):
            continue
        # Skips retweeted posts
        # TODO: expect Jedi to forget about this
        if weibo_post_info.get('retweeted_status'):
            continue

        # Processes long Weibo post
        if weibo_post_info['isLongText']:
            weibo_post_id_str: str = weibo_post_info['id']
            weibo_post_info = get_long_weibo(weibo_post_id_str)
            post = weibo.WeiboPost(weibo_post_info)
        else:
            post = weibo.WeiboPost(weibo_post_info)
        weibo_posts.append(post)

    return weibo_posts
Beispiel #2
0
def get_long_weibo(weibo_id_str: str) -> dict:
    long_weibo_url = f'https://m.weibo.cn/detail/{weibo_id_str}'
    html = requests_get(long_weibo_url).text
    html = html[html.find('"status":'):]
    html = html[:html.rfind('"hotScheme"')]
    html = html[:html.rfind(',')]
    html = '{' + html + '}'
    returned_json = json.loads(html, strict=False)
    return returned_json['status']
Beispiel #3
0
def get_user_info(user_id: int) -> dict or None:
    data = {'containerid': '100505' + str(user_id)}
    r = requests_get(url, data)
    returned_json = r.json()

    if not returned_json['ok']:
        return None

    info = returned_json['data']['userInfo']
    if info.get('toolbar_menus'):
        del info['toolbar_menus']
    user_info = standardize_info(info)
    return user_info