我的代码适用于通过Python的Tweepy包获取实时推文。我只想获取推文的创建日期和内容,所以我定义如下
def on_status(self, status):
tweet_text = status.text
tweet_created_date = str(status.created_at)
tweet_data = {'Created_at':tweet_created_date,'Text':tweet_text}
self.num_tweets += 1
if self.num_tweets < 10001:
with open('data.txt','a') as tf:
#tf.write(tweet_data + '\n')
tf.write(format(tweet_data) + '\n')
return True
else:
return False
但输出并未完全显示“Created_at:....., Text.....”。它会随着创建日期的变化而变化。
{'Text': 'RT @owen_author: Tiger Lily of Bangkok: a serial killer is on the loose in #BKK NaNoWriMo winner #Bangkoknoir #thri…', 'Created_at': '2017-06-01 22:18:28'}
{'Text': 'RT @MidwestBG: #NP Silent Stranger @SilentStranger6 - Bangkok by Night (Alternate Mix) on @MidwestBG', 'Created_at': '2017-06-01 22:18:38'}
{'Text': 'RT @IronWavesRadio: #NP Silent Stranger @SilentStranger6 - Bangkok by Night (Alternate Mix) on @IronWavesRadio', 'Created_at': '2017-06-01 22:18:42'}
{'Created_at': '2017-06-02 02:34:31', 'Text': '"RT @EXOXIUMINMAMA: 17.06.10\n2017 BANGKOK SUPER LIVE \n#2017bkksuperlive \n\n#XIU의미소가우리에겐최고! \nXIUMIN's Smile is the BEST! \n\nรายละเอียด\n… "'}
{'Created_at': '2017-06-02 02:34:39', 'Text': '(w1-59)Stamps,Thailand stamps,MNH,wild animals,art,minerals #thailand #bangkok'}
{'Created_at': '2017-06-02 02:34:42', 'Text': 'RT @joeybirlem: reacting to cringey musicallys youtube video out tomorrow! bangkok vlog out on friday be readyyyyyyy'}
那么,我该如何解决这一天所有推文的问题,以 1 种形式“Created_at:....., Text.....”显示。
我是初学者,所以我需要你的帮助。
非常感谢。