【发布时间】:2018-05-19 21:54:28
【问题描述】:
我正在尝试分析政治推文。
当我运行这段代码时:
import tweepy
from tweepy import OAuthHandler
import datetime
consumer_key = '...'
consumer_secret = '...'
access_token = '...'
access_secret = '...'
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)
username = "VP"
startDate = datetime.datetime(2017, 12, 1, 0, 0, 0)
endDate = datetime.datetime(2017, 12, 2, 0, 0, 0)
tweets = []
tmpTweets = api.user_timeline(username)
for tweet in tmpTweets:
if tweet.created_at < endDate and tweet.created_at > startDate:
tweets.append(tweet)
while (tmpTweets[-1].created_at > startDate):
print("Last Tweet @", tmpTweets[-1].created_at, "...fetching more")
tmpTweets = api.user_timeline(username, max_id = tmpTweets[-1].id)
for tweet in tmpTweets:
if tweet.created_at < endDate and tweet.created_at > startDate:
tweets.append(tweet)
for tweet in tweets:
print(tweet.created_at)
我明白了:
Last Tweet @ 2017-12-02 13:52:36 ...fetching more
2017-12-01 21:06:35
2017-12-01 12:29:27
2017-12-01 12:27:36
2017-12-01 00:50:17
2017-12-01 00:47:42
2017-12-01 00:25:32
但这是错误的。 VP 在 12 月 1 日发了 3 次推文。这些时间戳似乎提前了 4 小时。如何在东部时间解决此问题?
【问题讨论】:
标签: python python-3.x datetime twitter tweepy