我试图制作一个Twitter文件夹,从文本文件发推文,但无法弄清楚如何段落。我希望它能够从每一行单独打印文本。像这样:
example tweet
and some text to accompany it
another example tweet
with some more text
这是我的支持代码。请注意,这仅用于读取/发布每一行。
import tweepy
from time import sleep
from credentials import*
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
my_file = open('quotes.txt')
file_lines = my_file.readlines()
my_file.close()
# Tweet a line every hour
def tweet():
for line in file_lines:
try:
print(line)
if line != '\n':
api.update_status(line)
sleep(3600)
else:
pass
except tweepy.TweepError as e:
print(e.reason)
sleep(2)
tweet()