4

tweepy を使用すると、次のような場所や複数の場所でツイートを検索できます。

stream.filter(locations=[-122.75,36.8,-121.75,37.8,-74,40,-73,41], track=terms)

しかし、NYのつぶやきをすべて1つのリストに、SFのつぶやきを別のリストに入れようとすると、どちらのリストにも割り当てられません。これは私のコードフラグメントです:

NY = 74,40,-73,41
NewYorkCNN = []
if status.coordinates == NY or status.place == 'New York':
    for term in terms:
        if term in status.text:
            NewYorkCNN.append(term)

それらを正しいリストに正しく配置するにはどうすればよいでしょうか?

4

1 に答える 1

3

あなたはおそらく今までに答えを見つけたでしょうが、それは私も苦労したことであり、しばらくすると十分に簡単な解決策を見つけました.

座標を確認し、つぶやきデータを英国または米国のデータベースに割り当てるかどうかを判断する方法を次に示します。

[1] または [2] が後に続く「座標」キーワードは、ツイートから緯度/経度のメタデータを取得し、それを下の行で割り当てられた境界と比較します。

これが役立つことを願っています:)

class CustomStreamListener(tweepy.StreamListener):

  def check_ukcoords(self, status):
      if status.coordinates is not None:
          lat = status.coordinates['coordinates'][1]
          lng = status.coordinates['coordinates'][0]        
          return 49.7 < lat < 58.8 and -6.1 < lng < 1.7

  def check_uscoords(self, status):
      if status.coordinates is not None:
          lat = status.coordinates['coordinates'][1]
          lng = status.coordinates['coordinates'][0]        
          return 25.1 < lat < 49.1 and -125 < lng < -60.5
于 2014-02-03T12:49:46.897 に答える