def dt_from_created created created created rsplit None if created 000

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
def dt_from_created(created):
created = created.rsplit(None, 2)
if created[1] == '+0000':
# timeline: Fri Jul 17 12:24:49 +0000 2009
dt = ' '.join([created[0], created[2]])
format = '%a %b %d %H:%M:%S %Y'
elif created[2] == '+0000':
# search: Thu, 16 Jul 2009 23:50:56 +0000
dt = ' '.join(created[:2])
format = '%a, %d %b %Y %H:%M:%S'
else:
logging.error('Timezone in the tweet date is not +0000, it\'s %s' %
created[1])
return datetime.now()
return datetime.strptime(dt, format)