我正在制作一个推特机器人,每次都会回复很多推文。所以我选择制作一个每15分钟运行一次的脚本,并从最后15分钟开始播放所有推文。我正在尝试将datetime包与tweepy包结合使用。遗憾的是,这不起作用。我正在尝试正确设置Tweepy游标的自动和直到变量。有人看到我的代码有问题吗?
while True:
query = ['word']
now = datetime.datetime.now()
previous = datetime.timedelta(minutes=15)
difference = now-previous
print (now, previous, difference)
con = psycopg2.connect("dbname='...' user='...' password='...'")
cur = con.cursor()
for tweet in tweepy.Cursor(api.search, q=query, since=difference, until=now, count=1000).items(10) :
print(tweet.created_at)
cur.execute("""INSERT INTO .......(created_at, tweet_id, tweet, reply_to_user_id, reply_to_screen_name, user_id, user_name, followers_count, retweet_count)
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)""",
(tweet.created_at,
tweet.id,
tweet.text,
tweet.in_reply_to_user_id,
tweet.in_reply_to_screen_name,
tweet.user.id,
tweet.user.name,
tweet.user.followers_count,
tweet.retweet_count))
con.commit()
time.sleep(900)