Skip to content
This repository has been archived by the owner on Nov 27, 2022. It is now read-only.

wafflespeanut/twitter-fetcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twitter Fetcher

A simple wrapper over the Twitter API to cache and serve tweets corresponding to a specified query.

Setup:

  • Create a new app in Twitter with read-only permission.
  • Create a new config.json file (matching the config.json.sample file).
  • Update the config with the search query along with the consumer key and consumer secret from your app.

Usage:

from fetch import TweetFetcher

f = TweetFetcher()      # defaults

In order to keep the local database updated (with a background worker), run

f.run_worker()      # non-blocking

To stop the worker thread, run

f.kill_worker()

To get 10 latest tweets from the local DB, run

tweets = f.get_last(10)
print map(lambda tweet: tweet['text'], tweets)

Design:

The goal of this wrapper is to serve the latest tweets (corresponding to the specified search query in the config) regardless of the API rate limitation imposed by Twitter. So, it makes use of a background worker which sends API requests every two seconds and keeps the local database in sync with the latest tweets matching that query. This allows us to independently fetch any number of latest tweets (limited by the cache size) any time.

The config is read only by the worker, and it reads it every time before populating the database. This means that whenever the config gets changed, it will be reflected in the database during the next iteration.

About

Fetch and maintain a cache of tweets for a given query

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages