繁体   English   中英

使用Tweepy按位置对推文进行排序

[英]Using Tweepy to sort tweets by location

使用tweepy,我们可以按位置和多个位置搜索推文,例如:

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

然而,当我尝试将来自NY的所有推文放在一个列表中,并将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)

他们怎么能正确地放在正确的列表中?

你现在可能已经找到了答案,但这也是我一直在努力的事情,经过一段时间后发现了一个简单的解决方案。

以下是我检查坐标的方法,并确定是否将推文数据分配到英国或美国数据库。

后跟[1]或[2]的“coordinates”关键字从推文中获取纬度/经度元数据,并将其与下面一行中指定的边界进行比较。

我希望这有帮助 : )

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM