python - Tweepy CustomStreamListener Class -
i have following code have made amendments class 'customstreamlistener':
import sys import tweepy consumer_key="" consumer_secret="" access_key = "" access_secret = "" auth = tweepy.oauthhandler(consumer_key, consumer_secret) auth.set_access_token(access_key, access_secret) api = tweepy.api(auth) class customstreamlistener(tweepy.streamlistener): def on_status(self, status): hashtag in status.entities['hashtags']: if hashtag == 'turndownforwhat': print(hashtag['text']) print status.text def on_error(self, status_code): print >> sys.stderr, 'encountered error status code:', status_code return true # don't kill stream def on_timeout(self): print >> sys.stderr, 'timeout...' return true # don't kill stream sapi = tweepy.streaming.stream(auth, customstreamlistener()) sapi.filter(locations=[-122.75,36.8,-121.75,37.8])
the bit have added within class 'for' statement onwards. trying filter text values of hashtags within text messages , use of standard tweepy filters further down filter geolocation.
this has been built in python 2.7. amendments code not error hangs no tweets coming through. have put logical error in somewhere have missed?
thanks
the code has error in "if hashtag" condition.
it should be:
if hashtag['text'] == 'turndownforwhat'
you may need wait while find tweet shows up, if use bigger bounding box , trending hashtag see results modification.
Comments
Post a Comment