twitter api ビールのつぶやきを収集する pythonコード
あまり長いと(時間がかかると?)
details: {"error":"Invalid query"}
が返ってくるので注意.
10x100=1000ツイートを1時間ごとにcronで種集すればとりあえずは良い感じ.
しばらく様子を見る.
#!/usr/bin/python # -*- coding: utf-8 -*- import twitter import json import codecs twitter_search = twitter.Twitter(domain="search.twitter.com") search_results = [] for page in range(1,11): search_results.append(twitter_search.search(q="ビール", rpp=100, page=page)) tweets = [r['text'] \ for result in search_results \ for r in result['results']] ttime = [r['created_at'] \ for result in search_results \ for r in result['results']] tuser = [r['from_user'] \ for result in search_results \ for r in result['results']] f = codecs.open("/home/kubota/twitter/tweet.txt","a","utf-8") for itweets in range(1, len(tweets)): f.write(ttime[itweets]) f.write('\n') f.write(tuser[itweets]) f.write('\n') f.write(tweets[itweets]) f.write('\n') f.close()