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]
评论列表
文章目录