def get_twitter_stream(): stream = TwitterStream( domain="userstream.twitter.com", api_version="1.1", auth=OAuth(**TWITTER), ) return stream.user()
def get_twitter_stream(): stream = TwitterStream( domain="userstream.twitter.com", api_version="1.1", auth=OAuth(**TWITTER), ) return stream.user()
def _follow_userstream(bot): o = service.config_for(bot).oauth._fields stream = TwitterStream(auth=twitter.OAuth(**o), domain="userstream.twitter.com", block=False) for msg in stream.user(): if msg is not None: service.logger.debug(str(msg)) # Twitter signals start of stream with the "friends" message. if 'friends' in msg: _announce(bot, "\x02twitter:\x02 This channel is now streaming Twitter in real-time.") elif 'text' in msg and 'user' in msg: service.storage_for(bot).last = msg url_format = "(https://twitter.com/{0[user][screen_name]}/status/{0[id_str]})" if 'retweeted_status' in msg: text = "\x02[@{0[user][screen_name]} RT @{0[retweeted_status][user][screen_name]}]\x02 {0[retweeted_status][text]} " + url_format else: text = "\x02[@{0[user][screen_name]}]\x02 {0[text]} " + url_format _announce(bot, text.format(msg)) else: time.sleep(.5) if not service.storage_for(bot).active: return
def main(): username = '******' quotes = 'quotes.txt' #Opens quotes file for quotes of anguish (line fo each quote) with open(quotes) as f: quotes = [line.strip() for line in f if line != "\n"] pprint(quotes) auth = OAuth(ACCESS_TOKEN, ACCESS_TOKEN_SECRET, API_KEY, API_SECRET) t = Twitter(auth=auth) ts = TwitterStream(domain='userstream.twitter.com', auth=auth) stream = ts.user() for tweet in stream: #pprint(tweet) if 'event' in tweet: print('received event %s' % tweet['event']) elif 'hangup' in tweet: return elif 'text' in tweet and tweet['user']['screen_name'] != username: print('from @%s: %s' % (tweet['user']['screen_name'], tweet['text'])) line = random.choice(quotes) print('responding with line: %s' % line) reply = '@' + tweet['user']['screen_name'] + ' ' + line t.statuses.update(status=reply, in_reply_to_status_id=tweet['id'])
def main(): username = '******' quotes = 'quotes.txt' #Opens quotes file for quotes of anguish (line fo each quote) with open(quotes) as f: quotes = [line.strip() for line in f if line != "\n"] pprint(quotes) auth = OAuth(ACCESS_TOKEN, ACCESS_TOKEN_SECRET, API_KEY, API_SECRET) t = Twitter(auth=auth) ts = TwitterStream(domain='userstream.twitter.com', auth=auth) stream = ts.user() for tweet in stream: #pprint(tweet) if 'event' in tweet: print('received event %s' % tweet['event']) elif 'hangup' in tweet: return elif 'text' in tweet and tweet['user']['screen_name'] != username: print('from @%s: %s' % (tweet['user']['screen_name'], tweet['text'])) line = random.choice(quotes) print('responding with line: %s' % line) reply = '@' + tweet['user']['screen_name'] + ' ' + line t.statuses.update(status=reply, in_reply_to_status_id=tweet['id'])
def stream(self): """Listens to your feed, and updates it whenever someone posts a new tweet.""" twitter_stream = TwitterStream(auth=authenicate(), domain='userstream.twitter.com') for data in twitter_stream.user(): self.feed.values = self.update_feed(data)
def stream(self): """Listens to your feed, and updates it whenever someone posts a new tweet.""" twitter_stream = TwitterStream(auth=authenicate(), domain='userstream.twitter.com') for data in twitter_stream.user(): self.feed.values = self.update_feed(data)
def open_stream(self): """ Opens an interface to the Twitter API and opens a stream. """ t = Twitter(auth=self.auth) ts = TwitterStream(domain='userstream.twitter.com', auth=self.auth) self.twitter = t self.stream = ts.user() self.iterator = iter(self.stream)
def open_stream(self): """ Opens an interface to the Twitter API and opens a stream. """ t = Twitter(auth=self.auth) ts = TwitterStream(domain='userstream.twitter.com', auth=self.auth) self.twitter = t self.stream = ts.user() self.iterator = iter(self.stream)
def GetTimeLineSteam(self, compositionRunner=None, block=True): while True: try: twitter_stream = TwitterStream( domain="userstream.twitter.com", api_version="1.1", auth=OAuth(oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET), block=block) iterator = twitter_stream.user() for tweet in iterator: self.ProcessTweet(tweet, compositionRunner) except Exception: time.sleep(60)
def _follow_userstream(ctx): o = ctx.config.oauth._fields stream = TwitterStream(auth=twitter.OAuth(**o), domain="userstream.twitter.com", block=False) reconnect_seconds = [2, 10, 60, 300] reconnect_tries = 0 while ctx.storage.active: try: for msg in stream.user(): if msg is not None: service.logger.debug(str(msg)) # Twitter signals start of stream with the "friends" message. if 'friends' in msg: _announce(ctx, "\x02twitter:\x02 This channel is now streaming Twitter in real-time.") reconnect_tries = 0 elif 'text' in msg and 'user' in msg: memorize_id(ctx, msg["id_str"]) ctx.storage.last = msg url_format = "(https://twitter.com/{0[user][screen_name]}/status/{0[id_str]})" if 'retweeted_status' in msg: text = "\x02[@{0[user][screen_name]} RT @{0[retweeted_status][user][screen_name]}]\x02 {0[retweeted_status][text]} " + url_format else: text = "\x02[@{0[user][screen_name]}]\x02 {0[text]} " + url_format _announce(ctx, text.format(msg)) else: time.sleep(.5) if not ctx.storage.active: return _announce(ctx, "\x02twitter:\x02 Twitter userstream connection lost! Waiting {time} seconds to reconnect.".format( time=reconnect_seconds[reconnect_tries] )) except Exception as e: _announce(ctx, "\x02twitter:\x02 Exception thrown while following userstream! Waiting {time} seconds to reconnect.".format( time=reconnect_seconds[reconnect_tries] )) _announce(ctx, "↳ {name}: {info}".format( name=e.__class__.__name__, info=str(e) )) time.sleep(reconnect_seconds[reconnect_tries]) reconnect_tries += 1
def main(): # open up a file and get a list of lines of lyrics (no blank lines) with open(LYRICS) as lyrics_file: lyrics = [line.strip() for line in lyrics_file if line != "\n"] # get twitter api ready auth = OAuth(ACCESS_TOKEN, ACCESS_TOKEN_SECRET, API_KEY, API_SECRET) t = Twitter(auth=auth) ts = TwitterStream(domain='userstream.twitter.com', auth=auth) # open up our user's stream stream = ts.user() # iterate through every event for tweet in stream: # Print it out nicely, so we can see what happens. pprint(tweet) if 'event' in tweet: print('received event %s' % tweet['event']) elif 'hangup' in tweet: return elif 'text' in tweet and tweet['user']['screen_name'] != USERNAME: # 'text' means that this is a tweet. If the screen name wasn't our # own, this is someone tweeting at us. # print out the important bits print('from @%s: %s' % (tweet['user']['screen_name'], tweet['text'])) # Pick a lyric, compose a reply, and send it! line = random.choice(lyrics) print('responding with line: %s' % line) reply = '@' + tweet['user']['screen_name'] + ' ' + line # Make sure the reply is 140 characters... reply = reply[:140] t.statuses.update(status=reply, in_reply_to_status_id=tweet['id'])
def main(): # open up a file and get a list of lines of lyrics (no blank lines) with open(LYRICS) as lyrics_file: lyrics = [line.strip() for line in lyrics_file if line != "\n"] # print out our list of lyrics (for diagnostics) pprint(lyrics) # get twitter api ready auth = OAuth(ACCESS_TOKEN, ACCESS_TOKEN_SECRET, API_KEY, API_SECRET) t = Twitter(auth=auth) ts = TwitterStream(domain='userstream.twitter.com', auth=auth) # open up our user's stream stream = ts.user() # iterate through every event for tweet in stream: # Print it out nicely, so we can see what happens. pprint(tweet) if 'event' in tweet: print('received event %s' % tweet['event']) elif 'text' in tweet and tweet['user']['screen_name'] != USERNAME: # 'text' means that this is a tweet. If the screen name wasn't our # own, this is someone tweeting at us. # print out the important bits print('from @%s: %s' % (tweet['user']['screen_name'], tweet['text'])) # Pick a lyric, compose a reply, and send it! line = random.choice(lyrics) print('responding with line: %s' % line) reply = '@' + tweet['user']['screen_name'] + ' ' + line t.statuses.update(status=reply, in_reply_to_status_id=tweet['id'])
def run(config, verbose=True): uid = config['user_id'] auth = OAuth( config['token'], config['token_secret'], config['consumer_key'], config['consumer_secret']) log = Logger(config['log_path']) print('connecting %d...' % uid) stream = TwitterStream(domain='userstream.twitter.com', auth=auth) for obj in stream.user(): if verbose: if 'event' in obj: print('event: %s' % obj['event']) elif 'in_reply_to_status_id' in obj: print('tweet by %s' % obj['user']['screen_name']) elif 'friends' in obj: print('friends list obtained, streaming begins') else: print(repr(obj)) log.log(json.dumps(obj)) print('connection lost for %d' % uid)
auth = OAuth( creds["access_token"], creds["access_token_secret"], creds["consumer_key"], creds["consumer_secret"] ) twitter = Twitter(auth=auth) t_up = Twitter(domain='upload.twitter.com', auth=auth) twitter_stream = TwitterStream(auth=auth, domain="userstream.twitter.com" ) for tweet in twitter_stream.user(): # print msg # with open("test.json", "rb") as testf: # tweet = json.load(testf) # print json.dumps(tweet,indent=2) if "place" in tweet and tweet["place"] is not None: print "Tweet From", tweet["user"]["screen_name"], tweet["place"] bb = tweet["place"]["bounding_box"] if bb["type"] == "Polygon": min_lat = 90 max_lat = -90 min_lon = 180 max_lon = -180
db='thereminderbot') cursor = conn.cursor() reminder_str = "INSERT INTO reminders (SENDER, HOUR, MINUTE, PERIOD, " \ "TIME_ZONE, MONTH, DAY, MSG, FOLLOWING) VALUES ('{0}', {1}," \ " {2}, '{3}', '{4}', {5}, {6}, '{7}', {8});".format(tweet_obj.sender, tweet_obj.hour, tweet_obj.minute, tweet_obj.period, tweet_obj.time_zone, tweet_obj.month, tweet_obj.day, tweet_obj.msg, tweet_obj.following) cursor.execute(reminder_str) conn.commit() cursor.close() conn.close() return for msg in twitter_userstream.user(): if 'direct_message' in msg: try: tweet_obj = create_tweet(msg) if tweet_obj is None: raise CreateTweetError if (filter_tweet(tweet_obj) == False): raise FilterError if (time_check(tweet_obj) == False): raise TimePassedError except CreateTweetError: print("Could not create tweet_obj") update_log("Console", "Could not create tweet_obj") continue except FilterError:
user = "******" if __name__ == '__main__': try: oauth = OAuth(access_token, access_token_secret, consumer_key, consumer_secret) # Connect to Twitter Streaming API. Connect to the userstream domain twitter_stream = TwitterStream(domain="userstream.twitter.com", auth=oauth, secure=True) # Start streaming twitter feeds tweet_iterator = twitter_stream.user() for tweet in tweet_iterator: #entities = tweet.get("entities") entities = tweet.get("extended_entities") #print json.dumps(entities, indent=2, sort_keys=True) if (entities): media_list = entities.get("media") if (media_list): for media in media_list: if (media.get("type", None) == "photo"): # Retrieve twitter meta data twitter_data = {} description = tweet.get("user").get("description") loc = tweet.get("user").get("location")