私はtweepy +を使ってpythonで特定の領域からツイートの場所を抽出しようとしています。これをCSVファイルに書き出します。 私は、Pythonにあまりないですが、私は一緒に次sript作品の種類入れて管理することができます:それは(30分あたり10のエントリのように)非常にゆっくりと座標を抽出することを、TwitterのつぶやきのCoordinatesとTimeStampを特定のバウンディングボックスでPython/Tweepyで取得するにはどうすればよいですか?
import json
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
#Enter Twitter API Key information
consumer_key = 'cons_key'
consumer_secret = 'cons_secret'
access_token = 'acc_token'
access_secret = 'acc-secret'
file = open("C:\Python27\Output2.csv", "w")
file.write("X,Y\n")
data_list = []
count = 0
class listener(StreamListener):
def on_data(self, data):
global count
#How many tweets you want to find, could change to time based
if count <= 100:
json_data = json.loads(data)
coords = json_data["coordinates"]
if coords is not None:
print coords["coordinates"]
lon = coords["coordinates"][0]
lat = coords["coordinates"][1]
data_list.append(json_data)
file.write(str(lon) + ",")
file.write(str(lat) + "\n")
count += 1
return True
else:
file.close()
return False
def on_error(self, status):
print status
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
twitterStream = Stream(auth, listener())
#What you want to search for here
twitterStream.filter(locations=[11.01,47.85,12.09,48.43])
問題はあるが。これをもっと速くする方法がありますか?
各ツイートのタイムスタンプを追加するにはどうすればよいですか? 特定の地域で可能なすべてのつぶやきを取得する方法がありますか?(最大値は過去1週間のすべてのつぶやきです)
ありがとうございます!
ありがとう@Andy!このコードがPowerTrack APIで動作するかどうか知っていますか?より多くの量のツイート(無料でアクセスできるようにする必要はありません)を照会する方法はありますか? – Sebastian
この正確なコードはPowerTrackでは機能しません(エンドポイントが異なり、クエリ構文も同じです)。無料アクセスという点では、あなたが実際に持っている唯一のオプションは、リアルタイムではなくポーリングである標準の検索エンドポイントです。その代わりにそれを呼び出すことができますが、地理的/位置情報のデータが添付されているツイートの量に関してはまだ制限があります。 –