這是我的一個項目中的一部分代碼,我正在試圖發佈推文,我計劃將其保存到Google App Engine的數據庫中。對我來說,能夠獲得座標的緯度和長度值是非常重要的。 (我打算在繪製這些。)if語句來檢查座標是否在一個範圍內
目前的結果是這個樣子......
「的鳴叫文本」 @刪節不知道,說實話......作爲谷歌的產品,你會也這樣覺得。他們可能在網上商店有官方擴展。 \'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不是無」來檢查座標是否在一個範圍內。即Lat 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
我建議縮寫的名稱,並通過解包分配('緯度,經度= coordinates'),但另有我同意這個解決方案。 – Alfe
非常感謝你,代碼運行(&是超級有用的),但它似乎無法訪問座標。這是座標數據提供的格式:{u'type':u'Point',u'coordinates':[52.569001,-2.7846582]} – William
&這就是我的代碼目前的樣子... class def on_status(self,status): def check_coords(self,status): lat = status.coordinates [1] lng =狀態。座標[0] 返回49
William