tweepy

Tweepy: Stream data for X minutes?

孤者浪人 提交于 2019-12-05 22:16:28
I'm using tweepy to datamine the public stream of tweets for keywords. This is pretty straightforward and has been described in multiple places: http://runnable.com/Us9rrMiTWf9bAAW3/how-to-stream-data-from-twitter-with-tweepy-for-python http://adilmoujahid.com/posts/2014/07/twitter-analytics/ Copying code directly from the second link: #Import the necessary methods from tweepy library from tweepy.streaming import StreamListener from tweepy import OAuthHandler from tweepy import Stream #Variables that contains the user credentials to access Twitter API access_token = "ENTER YOUR ACCESS TOKEN"

Tweepy. Make stream run forever

烈酒焚心 提交于 2019-12-05 20:29:50
I am relatively new to tweepy python library. I want to be sure that my stream python script always runs on a remote server. So it would be great if someone will share the best practices on how to make it happen. Right now I am doing it this way: if __name__ == '__main__': while True: try: # create instance of the tweepy tweet stream listener listener = TweetStreamListener() # set twitter keys/tokens auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) # create instance of the tweepy stream stream = Stream(auth, listener) stream.userstream

How to get tweets of a particular hashtag in a location in a tweepy?

倖福魔咒の 提交于 2019-12-05 19:48:30
问题 I wish to obtain tweets of a particular hashtag from a a particular location say Chennai for analysing data. I'm really new to Twitter API and tweepy. I found that the search url would look like this : https://api.twitter.com/1.1/search/tweets.json?q=%23cricket&geocode=-22.912214,-43.230182,1km&lang=pt&result_type=recent How do the same in tweepy ? Code so far : import tweepy ckey = "" csecret = "" atoken = "" asecret = "" OAUTH_KEYS = {'consumer_key':ckey, 'consumer_secret':csecret, 'access

Error with tweepy OAuthHandler

六月ゝ 毕业季﹏ 提交于 2019-12-05 16:08:41
I'm new here and kind of unexperienced with python, so sorry if the question is trivial. I have this simple script, to fetch followers of a given twitter user: import time import tweepy consumer_key="xxx" consumer_secret="yyy" access_token="zzz" access_token_secret="www" auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) of course xxx,yyy,etc are being set in my script with API key, secret, access token etc I get this error: c:\Development>c:\Python27\python.exe get_followers.py Traceback (most recent call last): File "get

Twitter API - Get number of followers of followers

筅森魡賤 提交于 2019-12-05 11:31:29
I'm trying to get the number of followers of each follower for a specific account (with the goal of finding the most influencial followers). I'm using Tweepy in Python but I am running into the API rate limits and I can only get the number of followers for 5 followers before I am cut off. The account I'm looking at has about 2000 followers. Is there any way to get around this? my code snippet is ids = api.followers_ids(account_name) for id in ids: more = api.followers_ids(id) print len(more) Thanks You don't need to get all user followers in order to count them. Use followers_count property. E

Converting time to epoch (Python) [duplicate]

倖福魔咒の 提交于 2019-12-05 11:28:25
This question already has an answer here: Convert string date to timestamp in Python 13 answers I am using tweepy to get a tweet. I am trying to send this tweet over Slack. Tweepy gives the time in a strange format, and Slack requires the time in epoch. for i in tweets: created=(i.created_at) print(created) print(created.strftime('%s')) This returns 2017-01-17 14:36:26 Traceback (most recent call last): File "C:\Users\Administrator\Desktop\slackbot3\run.py", line 287, in main print(created.strftime('%s')) ValueError: Invalid format string How can I get 2017-01-17 14:36:26 into epoch time? You

Tweepy: get old tweets now possible with Twitter search api?

南楼画角 提交于 2019-12-05 08:52:41
Accoring to http://www.theverge.com/2014/11/18/7242477/twitter-search-now-lets-you-find-any-tweet-ever-sent Twitter search now lets you find any tweet ever sent. But when i am trying to get tweets from 2014 to 2015 using tweepy it gets only recent: query = 'Nivea' max_tweets = 1000 searched_tweets = [json.loads(status.json) for status in tweepy.Cursor(api.search, q=query, count=100, #since_id="24012619984051000", since="2014-02-01", until="2015-02-01", result_type="mixed", lang="en" ).items(max_tweets)] I tried since="2014-02-01", and since_id but no matter. Unfortunately, you cannot access

Limit tweepy stream to a specific number

核能气质少年 提交于 2019-12-05 02:33:02
问题 class listener(StreamListener): def on_status(self, status): try: userid = status.user.id_str geo = str(status.coordinates) if geo != "None": print(userid + ',' + geo) else: print("No coordinates") return True except BaseException as e: print('failed on_status,',str(e)) time.sleep(5) def on_error(self, status): print(status) auth = OAuthHandler(ckey, csecret) auth.set_access_token(atoken, asecret) twitterStream = Stream(auth, listener()) twitterStream.filter(locations=[-97.54,32.55,-97.03,33

Getting the location using Tweepy

孤者浪人 提交于 2019-12-04 21:15:13
I am trying to figure out how to output the location of the twitter user only if they have it displayed. How would I go about doing that? Right now I have this: from tweepy import Stream from tweepy import OAuthHandler from tweepy.streaming import StreamListener import time import json from HTMLParser import HTMLParser ckey = '' csecret = '' atoken = '' asecret = '' class listener(StreamListener): def on_status(self, status): print status.text if status.coordinates: print 'coords:', status.coordinates if status.place: print 'place:', status.place.full_name return True on_event = on_status def

Tweepy multiple auth handler

旧街凉风 提交于 2019-12-04 18:50:02
I am using nirgs forked version of Tweepy , which I need to use to get tweets between 2017-01-31 and 2017-02-01 . My code works and due to Twitters Rate Limits I have to switch between multiple auth handlers to be able to work with tweets which dates are as far away as mentioned before. I am using this instruction , but after reaching Rate Limit and trying to switch to the next auth handler by using api.auth_idx += 1 I get the following error: File "build/bdist.macosx-10.11-intel/egg/tweepy/api.py", line 45, in auth_idx IndexError: Index out of bounds The main code looks something like this: