我想知道何时创建user
。以下脚本提供了所需的信息:
import sys
from tweepy import OAuthHandler
from tweepy import Stream
from tweepy.streaming import StreamListener
USER_KEY = ''
USER_SECRET = ''
ACCESS_TOKEN = ''
ACCESS_SECRET = ''
class StdOutListener(StreamListener):
def on_data(self, data):
tweet = json.loads(data)
account_created = tweet['user']['created_at']
print(account_created)
def on_error(self, status):
if status == 420:
sys.stderr.write('Enhance Your Calm; The App Is Being Rate Limited For Making Too Many Requests')
return True
else:
sys.stderr.write('Error {}n'.format(status))
return True
if __name__ == "__main__":
listener = StdOutListener()
auth = OAuthHandler(USER_KEY, USER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
stream = Stream(auth, listener)
stream.filter(languages=['en'], track=['Python'])
但是,输出显示如下:
Wed Mar 06 03:11:05 +0000 2019
如何将其转换为UNIX时间戳?
答案 0 :(得分:0)
You can try this: (tested with python 3.6)
from datetime import datetime
dt = datetime.strptime('Wed Mar 06 03:11:05 +0000 2019', '%a %b %m %H:%M:%S %z %Y')
print(dt.timestamp())