【发布时间】:2013-10-02 03:57:06
【问题描述】:
这是我尝试流式传输推文的项目中的部分代码,我计划将其保存到 Google App Engine 的数据库中。能够获得坐标的纬度和经度值对我来说很重要。 (我计划稍后再绘制这些。)
目前的结果看起来是这样的……
'tweet text'@REDACTED 不确定,说实话...作为 Google 产品,您会这么认为。他们可能在网上商店有官方扩展。 \“用户名”已删除 \'创建于't2013-09-26 08:39:45 \ '用'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”的位置,以检查坐标是否在一个范围内。即 Lat 50 - 55 和 long 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
【问题讨论】:
标签: python if-statement twitter geo tweepy