これは、Google App Engine のデータベースに保存する予定のツイートをストリーミングしようとしているプロジェクトのコードの一部です。座標の緯度と経度の値を取得できることが重要です。(これらは後でプロットする予定です。)
現在の結果は次のようになります...
'tweet text'@REDACTED 正直に言うとわかりません...Googleの製品として、あなたはそう思うでしょう。Web ストアに公式の拡張機能がある場合があります。\ 'User Name'REDACTED \ 'Created at't2013-09-26 08:39:45 \ 'Created with'tTwitter for Android \ 'geo't{u'type': u'Point', u'coordinates': [52.569001, -2.7846582]}\ 'coordinates't{u'type': u'Point', u'coordinates': [-2.7846582, 52.569001]}
私がやりたいのは、「status.coordinates が None でない場合」と表示されている場所を変更して、座標が範囲内にあるかどうかを確認することです。つまり、緯度 50 ~ 55、経度 0 ~ 5 です。
ありがとうございました!:)
class CustomStreamListener(tweepy.StreamListener):
def on_status(self, status):
if status.coordinates is not None:
try:
print "'tweet text'%s\n\ 'User Name't%s\n\ 'Created at't%s\n\ 'Created with't%s\n\ 'geo't%s\ 'coordinates't%s" % (status.text,
status.author.screen_name,
status.created_at,
status.source,
status.geo,
status.coordinates)
except Exception, e:
print >> sys.stderr, 'Encountered Exception:', e
pass
def on_error(self, status_code):
print >> sys.stderr, 'Encountered error with status code:', status_code
return True # Don't kill the stream
def on_timeout(self):
print >> sys.stderr, 'Timeout...'
return True # Don't kill the stream