Menu
  • HOME
  • TAGS

Trying to Install Tweepy using pip : Error “Can't load a json library”

python,pip,tweepy

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...

ImportError: No module named tweepy

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.

How do you use tweepy to search for tweets within a given timeframe?

python,twitter,tweepy

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....

replying to tweet with image using tweepy

python,twitter,tweepy

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.

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

python,twitter,tweepy

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....

How do I save streaming tweets in json via tweepy?

python,json,tweepy

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...

Error while filtering english language tweets only

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...

How to successfully get all the tweets for one user with tweepy?

python,tweepy

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.

Turkish characters in python

python,twitter,tweepy,turkish

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...

Is twitter streaming api exactly 1 percent of the whole streaming?

api,twitter,streaming,tweepy

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....

Is there a way to retrieve tweets in a specific trend?

python,twitter,tweepy

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...

Tracking hashtag with geolocation - tweepy

python,geolocation,tweepy

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

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

python,json,twitter,tweepy

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...

Cannot install tweepy on Rasbian with sudo pip install

python,raspberry-pi,tweepy

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 ...

iterate through a Twitter stream using tweepy

python,tweepy

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 ...

extracting hashtags out of Twitter trending topics data with Python Tweepy

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('#')...

tweepy error response status code 400

python,tweepy

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...

Getting tweets by date with tweepy

python,twitter,tweepy

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...

Error while installing tweepy on windows for python 2.7

python,python-2.7,tweepy

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...

Writing multiple JSON to CSV in Python - Dictionary to CSV

python,csv,dictionary,tweepy

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...

Tweepy: Stream data for X minutes?

python,twitter,tweepy

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...

How do I filter tweets using location AND keyword?

python,tweepy

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...

Error while fetching Tweets with Tweepy

python,mongodb,twitter,tweepy

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,...

tweepy how to get a username from id

python,tweepy

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 ...

Tweepy capping at 3182 tweets from a user

python,twitter,tweepy

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...

Heroku ImportError: No module named tweepy - but it's installed and runs fine locally

python,heroku,twitter,tweepy

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...

Posting a gif to twitter using tweepy

python,image,tweepy

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...

Retrieving tweet by tweet-id

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 =...

Convert Tweepy Status object into JSON

python,tweepy

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) ...

Consuming Twitter stream with tweepy and serving content via websocket with gevent

python,twitter,gevent,tweepy

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...

TypeError: Can't convert 'bytes' object to str implicitly

python,twitter,tweepy

I updated the API and installed it again! somebody improved that. it works now :)

since_ID in mentions_timeline returns most recent tweet - not sure if issue is with Python or Twitter API

python,twitter,tweepy

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...

Tweepy: How can I get more than 20 tweets from a user?

twitter,tweepy

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...

Following users who tweets a specific hashtag with tweepy for python?

python,twitter,tweepy

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...

Streaming Twitter direct messages

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....

Python script to follow Twitter user IDs

python,twitter,tweepy

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 ...

How to check the text of a tweet for a specific keyword from an array in python

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...

How to separate text from twitter streaming JSON responses and run analysis on text with python?

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....

Limit tweepy stream to a specific number

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...

Using regular expression in Twitter API

python,regex,twitter,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...

Can I use twitter api to search tweets one week before?

twitter,tweepy

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...

What is the difference between on_data and on_status in the tweepy library?

python,twitter,tweepy

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...

Remaining limits error

python,tweepy

[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',...

Python tweepy find all tweets in the Netherlands

python,tweepy,geocode

You can only set your query string to '*' when also using the geocode parameter. A search for q='*' without a specified geocode is invalid.

tweepy.error.TweepError: Twitter error response: status code = 401

python,tweepy

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...

Tweepy - Print All Fields from All User Objects

python,python-2.7,tweepy

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....

Understanding the Twitter rate limit

python,twitter,tweepy

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...

Loop error in tweepy

for-loop,printing,tweepy

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...

How to get follower count using tweepy

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...

Using Tweepy to listen to stream and search for tweets. How to stop previous search and only listen for new stream?

python,flask,tweepy

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...

Filtering in tweepy

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/...

Using Tweepy to extractonly the 'text' and 'language' fields, if present in homework

python,api,twitter,tweepy

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...

Getting tweet replies to a particular tweet from a particular user

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...

Tweepy location on Twitter API filter always throws 406 error

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. :(...

How to stream twitter mentions with tweepy?

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"...

Filter images from tweets

python,tweepy

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...

Running python tweepy listener

python,twitter,tweepy

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 - Tweepy - How to get rate_limit_status()?

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...

Return the number of remaining hits tweepy

python,tweepy

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...