How to get Twitter current time?


#1

Hi guys, I need to get twitter current time to compare with a tweet ‘created_at’ time and I don’t know how to do that. Here in the discussion I saw something about read from the ‘date’ header from an api call but, I can’t find when I print a dir(api_call). Is it need to be a specific call? I don’t have experience in the area so what I tried was:


eu = api.me()
print dir(eu.status)
print dir(api)

There was no date header there.

Can someone, please, tell me which call should have a Date header?

ps: I’m using tweepy api.

Thanks a lot.


#2

Att: Now I know how to make the request and get the ‘Date’ with:

import requests r = requests.get("https://api.twitter.com/1.1/account/verify_credentials.json") twitter_time = r.headers.pop('date')

And it’s working, but I obtain a string like:
Sun, 20 Oct 2013 07:03:52 UTC

And in order to make comparisons I need to get the numbers individually or in Unix time.
I know I could make some string manipulation but I’m pretty sure that there is some easier way to do that.

Can anyone help me out?
Thanks!


#3

I think in Python you’ll want to parse the date using dateutil’s parser http://labix.org/python-dateutil#head-a23e8ae0a661d77b89dfb3476f85b26f0b30349c to get a date time object, then convert that date time to an epoch using .strftime(’%s’) or a more dedicated method.