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 data from Twitter using Tweepy and store in csv file

This will do the job! I will recommend you to use csv from Python. Open a file and write to it during your loop like this: #!/usr/bin/python import tweepy import csv #Import csv auth = tweepy.auth.OAuthHandler(‘XXXXXX’, ‘XXXXXXX’) auth.set_access_token(‘XXX-XXX’, ‘XXX’) api = tweepy.API(auth) # Open/create a file to append data to csvFile = open(‘result.csv’, ‘a’) #Use … Read more

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

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