Esempio n. 1
0
def updateWeiboById(mid):
    weibo = weibo_client.get('/showBatch', ids=int(mid))['statuses'][0]

    items = resp2item_search(weibo, 8)
    items2mongo(items, weibo_mode='REPOST')

    return weibo
Esempio n. 2
0
def updateWeiboById(mid):
    weibo = weibo_client.get('/showBatch', ids=int(mid))['statuses'][0]
        
    items = resp2item_search(weibo, 8)
    items2mongo(items, weibo_mode='REPOST')

    return weibo
Esempio n. 3
0
def getWeiboById(mid):
    weibo = mongo.master_timeline_weibo_repost.find_one({'_id': int(mid)})
    if weibo:
        return weibo
    else:
        weibo = weibo_client.get('/showBatch', ids=int(mid))['statuses'][0]

        items = resp2item_search(weibo, 8)
        items2mongo(items, weibo_mode='REPOST')

        return weibo
Esempio n. 4
0
def getWeiboById(mid):
    weibo = mongo.master_timeline_weibo_repost.find_one({'_id': int(mid)})
    if weibo:
        return weibo
    else:
        weibo = weibo_client.get('/showBatch', ids=int(mid))['statuses'][0]
        
        items = resp2item_search(weibo, 8)
        items2mongo(items, weibo_mode='REPOST')

        return weibo
Esempio n. 5
0
def index(mid, page=None):
    client = get_client()

    per_page = 200
    total_page = 0
    reposts_count = 0
    source_weibo = None
    if page is None:
        source_weibo = client.get('/showBatch', ids=mid)['statuses'][0]
        items = resp2item_search(source_weibo, 8)
        items2mongo(items, weibo_mode='REPOST')

        reposts_count = source_weibo['reposts_count']
        total_page = int(math.ceil(reposts_count * 1.0 / per_page))
        page = total_page
    else:
        source_weibo = mongo.db.master_timeline_weibo_repost.find_one({'id': mid})
        if source_weibo is None:
            return ''
        reposts_count = source_weibo['reposts_count']
        total_page = int(math.ceil(reposts_count * 1.0 / per_page))
    
    if page == 0:
        return ''
        
    # try:
    reposts = client.get('/queryReList', tweetId=mid, count=per_page, page=page)['reposts']

    # 如果reposts为空,且是最开始访问的一页,有可能是页数多算了一页,直接将页数减一页跳转
    if reposts == [] and total_page > 1 and page == total_page:
        return redirect(url_for('graph.index', mid=mid, page=page - 1))

    items = []
    for repost in reposts:
        items.extend(resp2item_search(repost, 4))
    items2mongo(items, weibo_mode='REPOST')

    for item in items:
        if isinstance(item, WeiboItem_search) and item['id'] != source_weibo['id']:
            item = item.to_dict()
            item['source_weibo'] = source_weibo['id']
            mongo.db.master_timeline_weibo_repost.update({'id': item['id']}, item, upsert=True)
    #except RuntimeError:
    #    pass
    
    reposts = list(mongo.db.master_timeline_weibo_repost.find({'source_weibo': source_weibo['id']}))
    if reposts == []:
        return ''

    page_count = total_page - page + 1 if total_page >= page else 0
    tree, tree_stats = reposts2tree(source_weibo, reposts, per_page, page_count)
    sort_results, max_depth, max_width = tree2graph(tree)
    
    tree_stats['max_depth'] = max_depth
    tree_stats['max_width'] = max_width

    # 存储转发状态
    tree_stats['id'] = mid
    tree_stats['page'] = page
    mongo.db.tree_stats.update({'id': mid, 'page': page}, tree_stats, upsert=True, w=1)
    
    return sort_results
Esempio n. 6
0
def index(mid, page=None):
    client = get_client()

    per_page = 200
    total_page = 0
    reposts_count = 0
    source_weibo = None
    if page is None:
        source_weibo = client.get('/showBatch', ids=mid)['statuses'][0]
        items = resp2item_search(source_weibo, 8)
        items2mongo(items, weibo_mode='REPOST')

        reposts_count = source_weibo['reposts_count']
        total_page = int(math.ceil(reposts_count * 1.0 / per_page))
        page = total_page
    else:
        source_weibo = mongo.db.master_timeline_weibo_repost.find_one(
            {'id': mid})
        if source_weibo is None:
            return ''
        reposts_count = source_weibo['reposts_count']
        total_page = int(math.ceil(reposts_count * 1.0 / per_page))

    if page == 0:
        return ''

    # try:
    reposts = client.get('/queryReList',
                         tweetId=mid,
                         count=per_page,
                         page=page)['reposts']

    # 如果reposts为空,且是最开始访问的一页,有可能是页数多算了一页,直接将页数减一页跳转
    if reposts == [] and total_page > 1 and page == total_page:
        return redirect(url_for('graph.index', mid=mid, page=page - 1))

    items = []
    for repost in reposts:
        items.extend(resp2item_search(repost, 4))
    items2mongo(items, weibo_mode='REPOST')

    for item in items:
        if isinstance(item,
                      WeiboItem_search) and item['id'] != source_weibo['id']:
            item = item.to_dict()
            item['source_weibo'] = source_weibo['id']
            mongo.db.master_timeline_weibo_repost.update({'id': item['id']},
                                                         item,
                                                         upsert=True)
    #except RuntimeError:
    #    pass

    reposts = list(
        mongo.db.master_timeline_weibo_repost.find(
            {'source_weibo': source_weibo['id']}))
    if reposts == []:
        return ''

    page_count = total_page - page + 1 if total_page >= page else 0
    tree, tree_stats = reposts2tree(source_weibo, reposts, per_page,
                                    page_count)
    sort_results, max_depth, max_width = tree2graph(tree)

    tree_stats['max_depth'] = max_depth
    tree_stats['max_width'] = max_width

    # 存储转发状态
    tree_stats['id'] = mid
    tree_stats['page'] = page
    mongo.db.tree_stats.update({
        'id': mid,
        'page': page
    },
                               tree_stats,
                               upsert=True,
                               w=1)

    return sort_results