私は、カスタム検索クエリによってさえずりをこすりするために、このPythonコードを見つけました:python scraperを使用してCSVに結果を保存するには?
https://github.com/tomkdickinson/Twitter-Search-API-Python/blob/master/TwitterScraper.py
私はcsvファイルにこのコードからの結果を格納します。
私は空白の
def save_tweets(self, tweets):
"""
Just prints out tweets
:return: True always
"""
for tweet in tweets:
# Lets add a counter so we only collect a max number of tweets
self.counter += 1
if tweet['created_at'] is not None:
t = datetime.datetime.fromtimestamp((tweet['created_at']/1000))
fmt = "%Y-%m-%d %H:%M:%S"
myCsvRow = log.info("%i [%s] - %s" % (self.counter, t.strftime(fmt), tweet['text']))
fd = open('document.csv','a')
fd.write(myCsvRow)
fd.close()
return True
としての私の検索クエリごとのようにツイートが、csvファイルの結果を出力し、forループの周りのライン245内でのCSVライターを追加しようとした。また、内のコメントがあります次のような170行目のコード:
@abstractmethod
def save_tweets(self, tweets):
"""
An abstract method that's called with a list of tweets.
When implementing this class, you can do whatever you want with these tweets.
"""
このクラスを使用してツイートを保存するにはどうすればよいですか?
答えとヒントをありがとう! –