you can cast Twitter created_at timestamps for Python dates like this:
import datetime, pymongo created_at = 'Mon Jun 8 10:51:32 +0000 2009'
and paste them into your Mongo collection as follows:
connection = pymongo.Connection('mymongohostname.com') connection.my_database.my_collection.insert({ 'created_at': dt, # ... other info about the tweet .... }, safe=True)
And finally, to get tweets in the last three days, first the newest:
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)]))
A. Jesse Jiryu Davis
source share