db.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:tweegraph 作者: PGryllos 项目源码 文件源码
def store_timeline(db_name, user_id, timeline):
    """stores the timeline as a list of json formated statuses in
    db -> db_name[user_id] under the key 'content'

    db_name  : name of the database
    user_id  : twitter id of user
    timeline : user timeline entity as returned by the twitter api
    """
    db_client = MongoClient()
    timeline = [status._json for status in timeline]

    if timeline:
        while True:
            try:
                db_client[db_name][str(user_id)].insert_one(
                        {'_id': user_id, 'content': timeline})
                break
            except DocumentTooLargeError as e:
                timeline = timeline[:-1]
            except WriteError as e:
                timeline = timeline[:-1]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号