This is not an error while trying to load a JSON library, but rather a Python syntax error caused by differences between Python 2 and Python 3 that happens to occur on a raise line. See the two lines that follow the raise line: raise ImportError, "Can't load a json...
I guess you could use twython and start with a search example wich you can modify to suit your needs . from twython import Twython, TwythonError # Requires Authentication as of Twitter API v1.1 twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) try: search_results = twitter.search(q='#python', count=50) except TwythonError as e: print...
Yes, in the post, @Adil Moujahid mentions that his code ran for 3 days. I adapted the same code and for initial testing, did the following tweaks: a) Added a location filter to get limited tweets instead of universal tweets containing the keyword. See How to add a location filter...
The Status object of tweepy itself is not JSON serializable, but it has a _json property which contains JSON serializable response data. For example: >>> status_list = api.user_timeline(user_handler) >>> status = status_list[0] >>> json_str = json.dumps(status._json) ...
You can't filter both things at once, you need to choose one and then check the other. Here you can find a more detailed answer to a similar question: How to add a location filter to tweepy module
I had this same problem, solved when I remved languages from the filter function since it's not yet functional, although Twitter says it is Instead I keep the check of the language as you did in the on_data(..) Also I use the on_status(..) instead of on_data(..) as follows: def on_status(self,...
I have done a similar thing with facebook's graph API (facepy module)! from tweepy.streaming import StreamListener from tweepy import OAuthHandler from tweepy import Stream import csv import json consumer_key="XXXX" consumer_secret="XXXX" access_token="XXXX" access_token_secret="XXXX" class StdOutListener(StreamListener): _headers = None def __init__(self,headers,*args,**keys): StreamListener.__init__(self,*args,**keys) self._headers = headers def on_data(self, data): json_data = json.loads(data) #data_header...
Twitter probably has limits on their api and will most likely block your api key if they feel that you are spamming. In fact I would bet there is a maximum number of tweets per day depending on the type of developer account. For stability and up time concerns running...
python-2.7,twitter,tweepy,data-extraction
The tweets are classified by Twitter on one language or another. Their classification isn't always correct. If the tweet uses multiple languages they just assign it to one of them. So you will need to filter them in your app against a dictionary or using some language detection libraries to...
This example shows you how to access how many tweets are remaining. print rate_limit_json["resources"]["search"]['/search/tweets']['remaining'] 180 "resources" is the key you should be using to access the information inside. If you want to update the value, put it in a loop reassigning the value after your time.sleep(). Put all the code...
python,python-3.x,twitter,tweepy,twitter-streaming-api
Your while logic is not working properly because Tweepy internally calls the on_status() method whenever it receives data. So you can't control the flow of by introducing a conditional inside an already running infinite loop, The best way is to create a new variable inside the class, which gets instantiated...
401 is the Unauthorized status code. It means that your credentials (in this case, your consumer/access tokens) are invalid. Try re-creating the credentials correctly again following the instructions here. Edit: If you're running exactly the code you posted, note that you must replace all the keys with the keys you...
class ListenerParser(StreamListener): def __init__(self, max_results): super(ListenerParser, self).__init__() self.texts = [] self.langs = [] self.count = 0 if max_results: self.max_results = max_results else: self.max_results = float("inf") ####This is the code I am responsible for as part of my homework### def on_data(self, data): data_refined = json.loads(data) if self.count<self.max_results: if data.has_key['text']: self.texts.append(data['text'].encode('utf-8')) if...
The Maths is pretty simple in this case, You are actually making 14 requests before twitter cuts you off, But you are able to fetch 280 names because tweepy.Cursor(api.followers, screen_name="NAME") is a single request which returns 20 values at a time, this means that you fetch 20 values for on...
Seems like this is not a tweepy issue, rather it is a windows issue. https://support.microsoft.com/en-us/kb/2525435 The issue state that the issue is with the C runtime libraries and visual studio. python setup.py install must be trying to compile some cython code inside tweepy - which may be needed for performance...
python,json,mongodb,twitter,tweepy
def on_data(self, data): datajson = json.loads(data) if any([i for i in filterKeywords if i in datajson["text"]]): """Do Desired function""" else: print('if statement not working') Simple mistake on your program, even after if condition works it may enter else in the next iteration. From your comments If you wish to avoid...
python,python-2.7,twitter,tweepy
Each API requests returns at most 5000 followers IDs at a time, to retrieve all the followers of the 200 000 companies, here is a very useful script from the book Mining the social web by Matthew A. Russell to solve the twitter api limit to make robust twitter request...
python,virtualenv,python-import,tweepy
Don't use sudo to call pip when you're in a virtualenv: the root user won't have the virtualenv activated so the package is installed globally, as you can see from the paths. Just run pip install tweepy.
Twitter unfortunately doesn't support searching of tweets using regular expressions which means that you do have to post process. There's not actually any official documentation from Twitter to that effect, but everyone who uses the Twitter search API post-processes their tweets using regex (including me). Since there isn't a stated...
python,twitter,tweepy,twitter-streaming-api
The code provided in the question is indeed correct. The problem was that I had forgot to regenerate the access token and secret after changing my application permissions to "Read, write and direct messages". Note: The direct messages arrive in the on_data() method rather than the on_direct_message() method....
In rereading your original question, I realize that you ask a lot of smaller questions. I'll try to answer most of them here but some may merit actually asking a separate question on SO. Why does it break with the addition of on_data ? Without seeing the actual error, it's...
Use Twitter Search: https://twitter.com/search-home Or: Google "twitter hashtag airAsia" or go to the address https://twitter.com/hashtag/airasia You can retrieve as many tweets as you want in any given trend. Note that method #1 of using Twitter's search engine allows you to search any keyword or trend, which isn't necessarily a...
That is may be because the tweepy throws error of type TweepError so you need to catch TweepError instead of TwitterError for line in f: try: api.CreateFriendship(userID) except TweepError,e: continue ...
python,twitter,real-time,tweepy
You can use the Streaming API to filter on tweets containing @mentions. When you filter the stream using the track parameter, filter by the username you're interested in by including the username in your track parameter like so: stream.filter(track=['twitterapi']) This will return to you all tweets containing the string "twitterapi"...
python,python-3.x,hashtag,tweepy
You find the tags in the status object. It is there you have to make the comparison with the ones you are looking for. example: for hashtag in status.entities['hashtags']: print(hashtag['text']) example here: http://www.pythoncentral.io/introduction-to-tweepy-twitter-for-python/...
Problem resolved (this problem, anyway). Install was aborting when it reached PIL in the requirements.txt file - it can't be installed via pip and was just skipping installing everything after it. I don't require PIL for this project so just removed it from requirements (I don't really know why it...
python-2.7,twitter,geolocation,tweepy
The issue here was the order of the coordinates. Correct format is: SouthWest Corner(Long, Lat), NorthEast Corner(Long, Lat). I had them transposed. :(...
python,twitter,tweepy,tweets,twitter-streaming-api
There is a workaround using the REST API. You will need the id_str and @username of the author of the original tweet you want to find replies to. You should use the Search API for the "@username" of the author. Go through the results looking for the 'in_reply_to_status_id' field to...
Below is some code that will cancel old streams when a new stream is created. It works by adding new streams to a global list, and then calling stream.disconnect() on all streams in the list whenever a new stream is created. diff --git a/app.py b/app.py index 1e3ed10..f416ddc 100755 --- a/app.py...
Solved, I think, by completely changing the method used to get tweets - I've used the cursor to iterate through them instead and it appears to be working. I don't really understand why it doesn't work without cursor though. query = '@name' max_tweets = 20 recent_mentions = [status for status...
Use Regular expressions to search the tweet. as follows import re keyword = ["iPhone", "Samsung", "HTC", "Sony", "Blackberry"] patterns = [r'\b%s\b' % re.escape(s.strip()) for s in keyword.lower()] there = re.compile('|'.join(patterns)) stream=["i have a iPhone","i dont like Samsung","HTC design are awesome","Sony camera is good","Blackberry lost market","Nokia soldout to windows"] for i...
You can make use of pages parameter in API.user_timeline([id/user_id/screen_name][, since_id][, max_id][, count][, page]). For page value 1, you will get a set of latest 20 tweets from the user timeline and then in further iteration, when we increase the value of page = 2 then the method returns other 20...
According to the documentation you need to use rpp keyword parameter to increase number of tweets per page. Twitter API returns 15 tweets if the parameter was not set in a request. Note, that Twitter search API endpoint returns no more than 100 tweets per page....
python,python-2.7,dictionary,twitter,tweepy
As per the Tweepy documentation Returns the remaining number of API requests available to the requesting user before the API limit is reached for the current hour. Calls to rate_limit_status do not count against the rate limit. If authentication credentials are provided, the rate limit status for the authenticating user...
I found that just converting the data gotten from the stream to json lets me use the data! class StreamListener(tweepy.StreamListener): def on_data(self, data): data = json.loads(data) print(data.text) def on_error(self, status_code): if status_code == 420: #returning False in on_data disconnects the stream return False ...
[Summarizing, clarifying and elaborating on the comment thread in the initial post] I get the same value, too ... unless/until I make a call to myapi.search, after which a lower value is returned. limits['resources'] contains a list of dictionaries for different resource families (types of API calls): ['account', 'blocks', 'users',...
This is a Twitter-side limitation. Per the documentation: This method can only return up to 3,200 of a user’s most recent Tweets. Native retweets of other statuses by the user is included in this total, regardless of whether include_rts is set to false when requesting this resource. Tweets beyond this...
Not exactly if they didn't change the way they sample from the time this blog post was written: http://blog.falcondai.com/2013/06/666-and-how-twitter-samples-tweets-in.html According to the article they send the tweets that where published between the 657th and the 666th millisecond. So it's not exactly 1% but a good approximation....
Tweets (their JSON-representation) contain a "media"-entity, as mentioned here. Tweepy should expose that type of entity as following, assuming there is an image included in the tweet: tweet.entities["media"]["media_url"] Therefore, if you want to store the image, you just need to download it, f.e. via python's request library. Try adding something...
json,parsing,tweepy,sentiment-analysis,twitter-streaming-api
from tweepy.streaming import StreamListener from tweepy import OAuthHandler from tweepy import Stream import json # Variables that contains the user credentials to access Twitter API access_token = '' access_token_secret = '' consumer_key = '' consumer_secret = '' # This is a basic listener that just prints received tweets to stdout....
You are iterating ids and i already contains element of ids. Try to pass i to lookup_users: for i in ids: print screen_name(api.lookup_users(i)) # print screen_name(api.lookup_users(ids[i])) update, try this way: users = api.lookup_users(user_ids=ids) for u in users: print u.screen_name ...
on_data() handles: replies to statuses deletes events direct messages friends limits, disconnects and warnings whereas, on_status() just handles statuses. source: https://github.com/tweepy/tweepy/blob/78d2883a922fa5232e8cdfab0c272c24b8ce37c4/tweepy/streaming.py...
Your code isn't broken, necessarily. Twitter limits you to returning 100 users with a GET user lookup (which is what api.lookup_users does). Requesting more than 100 will cause the Tweepy error code 18 which you got only for the followed users query, which looks like the user you queried follows...
You can only set your query string to '*' when also using the geocode parameter. A search for q='*' without a specified geocode is invalid.
python,twitter,hashtag,tweepy,trending
In your example you have a single entry in your list, consisting of nested dicts with key value 'trends' each value is a another dict, the one you are interested in is 'name' and in particular if it starts with '#': In [180]: [x for x in temp[0]['trends'] if x['name'].find('#')...
I updated the API and installed it again! somebody improved that. it works now :)
the solution i ended up with was switching to the twython module, which s the functionality well documented and working perfectly. thank you very much for your help.
Unfortunately, you can't get tweets older than a week with the twitter search API. Also note that the search results at twitter.com may return historical results while the Search API usually only serves tweets from the past week. - Twitter documentation. You can get specific tweets older than a week...
print userobjects[0].name prints the first object's username in the list. Just iterate for all objects in list and for whatever other fields you need inside that object....
Someone on the Raspberry Pi forums figured out the problem. Apparently there is a problem installing some applications with pip v1.1, which is the version in the Raspbian repository. Updating pip with the following command did the trick. sudo pip install -U pip ...
Outside of API limits, only the most recent 3000 tweets are available to anyone other than the account holder, even in the web interface. If you want the tweets before that, you'd need access to the archive.
I duplicated your code on my system (Windows 7, with Office 2010) and I got it working. I used your code but I simplified the search query as follows: search_results = api.search(q="canan1405", count=10) for tweet in search_results: print tweet.text.encode('utf-8') I pulled tweets from the 'canan1405' user as they contained Turkish...
python,twitter,tweepy,twitter-streaming-api
I'm not quite clear what it is you're after, but you can find tweets that match a certain tweet id using the following snippet (provided you have a consumer_key, consumer_secret, access_token, and access_token_secret from the Twitter API): import tweepy auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) public_tweets =...
The StreamListener runs on a gevent greenlet, and sends to all the websockets connected to the server the parsed coordinates. Tested with iocat localhost:10000 import gevent import gevent.monkey gevent.monkey.patch_all() from geventwebsocket.handler import WebSocketHandler from gevent import pywsgi from tweepy.streaming import StreamListener from tweepy import OAuthHandler from tweepy import Stream import...
Hopefully this will help someone else. Here is the solution and complete script. The Image import does not need to be used and there is a specific method to post media in tweepy. Thanks @jonrsharpe. This program will get a random image from a directory of images (gifs in my...
Unfortunately, you cannot access past data from Twitter. Is not a problem of what library you're using: Tweepy, Twitter4J, whatever, is just that Twitter won't provide any data that is older than more or less 2 weeks. To get historical data you'll need access to firehose, directly through Twitter or...
You can simply retrieve the tweets with the help of pages, Now on each page received you iterate over the tweets and extract the creation time of that tweet which is accessed using tweet.created_at and the you find the difference between the extracted date and the current date, if the...
This may be a bug that emerged in the 3.2.0 release of Tweepy. See this issue opened on GitHub. In that issue, TylerGlaiel notes that api.update_status fails if called thus: api.update_status('Test') But works if called like so: api.update_status(status='Test') I have also found this works. I imagine a fix will be...
You need to use the geocode parameter in Tweepy. Using the lat/long/radius from your search URL, your cursor should be defined like so: tweepy.Cursor(api.search, q='cricket', geocode="-22.9122,-43.2302,1km").items(10) See the Tweepy API.search documentation for more information on the parameters you can include in your search....