I use python-twitter to get the date of a tweet and try to parse it with the time.strptime()
function. When I do it interactively, everything works fine. When I call the program from my bash, I get a ValueError
saying (for example):
time data u'Wed Aug 12 08:43:35 +0000 2009' does not match
format '%a %b %d %H:%M:%S +0000 %Y'
Code looks like this:
api = twitter.Api(username='username', password='pw')
user = api.GetUser(username)
latest = user.GetStatus()
date = latest.GetCreatedAt()
date_struct = time.strptime(date, '%a %b %d %H:%M:%S +0000 %Y')
which throws the exception mentioned above.
It works on the interactive shell:
>>> user = api.GetUser('username')
>>> latest = user.GetStatus()
>>> date = latest.GetCreatedAt()
>>> date
u'Wed Aug 12 08:15:10 +0000 2009'
>>>> struct = time.strptime(date, '%a %b %d %H:%M:%S +0000 %Y')
>>>> struct
time.struct_time(tm_year=2009, tm_mon=8, tm_mday=12, tm_hour=8, tm_min=15, tm_sec=10, tm_wday=2, tm_yday=224, tm_isdst=-1)
Someone any idea why this is happening?
I am Using Ubuntu 9.04, Python 2.6.2 and python-twitter 0.6. All files in unicode.