可以解析Twitter的created_at時間戳Python的日期時間,像這樣:
import datetime, pymongo
created_at = 'Mon Jun 8 10:51:32 +0000 2009' # Get this string from the Twitter API
dt = datetime.strptime(created_at, '%a %b %d %H:%M:%S +0000 %Y')
,並把它們插入到你的蒙戈集合是這樣的:
connection = pymongo.Connection('mymongohostname.com')
connection.my_database.my_collection.insert({
'created_at': dt,
# ... other info about the tweet ....
}, safe=True)
最後,在最後三天內獲得的鳴叫,最新一:
three_days_ago = datetime.datetime.utcnow() - datetime.timedelta(days=3)
tweets = list(connection.my_database.my_collection.find({
'created_at': { '$gte': three_days_ago }
}).sort([('created_at', pymongo.DESCENDING)]))
可能取決於你所使用的映射。你能否在數據庫中檢查最後寫入的內容? – Thilo 2012-01-11 02:50:13