Managing Tweepy API Search

I originally worked out a solution based on Yuva Raj’s suggestion to use additional parameters in GET search/tweets – the max_id parameter in conjunction with the id of the last tweet returned in each iteration of a loop that also checks for the occurrence of a TweepError. However, I discovered there is a far simpler … Read more

Avoid Twitter API limitation with Tweepy

For anyone who stumbles upon this on Google, tweepy 3.2+ has additional parameters for the tweepy.api class, in particular: wait_on_rate_limit – Whether or not to automatically wait for rate limits to replenish wait_on_rate_limit_notify – Whether or not to print a notification when Tweepy is waiting for rate limits to replenish Setting these flags to True … Read more

Convert Tweepy Status object into JSON

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)

Get All Follower IDs in Twitter by Tweepy

In order to avoid rate limit, you can/should wait before the next follower page request. Looks hacky, but works: import time import tweepy auth = tweepy.OAuthHandler(…, …) auth.set_access_token(…, …) api = tweepy.API(auth) ids = [] for page in tweepy.Cursor(api.followers_ids, screen_name=”McDonalds”).pages(): ids.extend(page) time.sleep(60) print len(ids) Hope that helps.

How do I extend a python module? Adding new functionality to the `python-twitter` package

A few ways. The easy way: Don’t extend the module, extend the classes. exttwitter.py import twitter class Api(twitter.Api): pass # override/add any functions here. Downside : Every class in twitter must be in exttwitter.py, even if it’s just a stub (as above) A harder (possibly un-pythonic) way: Import * from python-twitter into a module that … Read more

How to add a location filter to tweepy module

The streaming API doesn’t allow to filter by location AND keyword simultaneously. Bounding boxes do not act as filters for other filter parameters. For example track=twitter&locations=-122.75,36.8,-121.75,37.8 would match any tweets containing the term Twitter (even non-geo tweets) OR coming from the San Francisco area. Source: https://dev.twitter.com/docs/streaming-apis/parameters#locations What you can do is ask the streaming API … Read more

tweepy get tweets between two dates

First of all the Twitter API does not allow to search by time. Trivially, what you can do is fetching tweets and looking at their timestamps afterwards in Python, but that is highly inefficient. You can do that by the following code snippet. consumerKey = “CONSUMER_KEY” consumerSecret = “CONSUMER_SECRET” accessToken = “ACCESS_TOKEN” accessTokenSecret = “ACCESS_TOKEN_SECRET” … Read more

tech