I'm trying to list out tweets with their time-stamps. I have this...
#!/usr/bin/python
import twitter
api = twitter.Api()
statuses = api.GetUserTimeline('ttytter')
for s in statuses:
  print s.created_at + " " + s.text
Which prints out...
Sat Oct 20 04:56:47 +0000 2012 @uriel1998 W/r/t DMs, they appear just fine in 2.0.4 and 2.1 beta here, near as I can tell.
Which is pretty much what I'm after, but for the time, which seems to be in the wrong timezone. https://twitter.com/ttytter/status/259518502069760000
Is there a way I can change this within the python-twitter library? I was looking at GetTimeZone() and SetTimeZone(), but I haven't been able to figure out how they work.
Also looking at how to shift a datetime object by 12 hours in python but not sure if I need to go there.
Thanks for any help!
 
                        
python-twitter returns the status timestamps as a string and as the number of seconds since the epoch. The latter is the simplest to convert to a timezone-aware
datetimeinstance (see this answer).Unfortunately the user's
time_zoneattribute is not in the standard tz database format used bypytz, so it is necessary to use theutc_offsetuser attribute instead (we still use thetime_zoneattribute to name thetzinfocreated with with the UTC offset). Thepython-dateutilpackage provides a convenience typetzoffsetthat allows the creation oftzinfoinstances from UTC offsets, which we can then use to convert thedatetimefrom UTC to the local time zone:which gives the output for the first status: