Skip to content

abhi11/twitter-trend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twitter API wrapper

This Python application can be used by application developers who intend to consume Application-only authenticated Twitter APIs.

Uses the REST API(Version 1.1)

List of API Currently Covered:

  • API to fetch from a User Timeline (statuses/user_timeline)
  • API to fetch current Trends (trends/place)
  • API to search tweets for a trend.
  • More will be added

Things you don't have to worry about

  • HTTPS Connnection.
  • Correct API URLs.
  • Authentication mechanism(Although, one needs to have an app registered with Twitter).
  • Most importantly, python version, it works on both 2.x and 3.x

Usage

  • Clone the repo first.
cd twitter-trend/ && touch twitter/constants.py
  • Add the following in the above created file
CONSUMER_KEY = your consumer key
CONSUMER_SECRET = your consumer secret
  • CONSUMER_KEY and CONSUMER_SECRET could be acquired by registering an app with Twitter Here. Login and create a new app ;-)
  • After adding the above lines in constants.py, come back to the root directory:
cd ~/twitter-trend
  • And run
sudo python setup.py install
  • To check whether installation is done, cd to tests and run the tests.
cd tests && python test.py
  • The above would also check whether CONSUMER_KEY and CONSUMER_SECRET are valid.

An Example to show the usability.

Creating a twitter-trend object -

from twitter.twrapper import *
twitter_obj = Twrapper(CONSUMER_KEY, CONSUMER_SECRET)

what this does is -

  • Authenticates application using key and secret.
  • Stores the obtained token for later requests.

Now you can use this twitter_obj to fetch data. Let's say you want to fetch the latest couple of tweets from Leonardo DiCaprio, from his Twitter handle - @LeoDiCaprio

tweets = twitter_obj.get_user_timeline_tweets("LeoDiCaprio", 2)

and that's it!

Check out test.py which contains examples demonstrating different calls.

Time Zone Wise Contribution to trends

  • Takes 100 tweets for every trending topic and pushes it into a database(trend_insert.py).[Yet to be ported]
  • Prints Time-Zone wise contribution for each trending topic(calculate.py).[Yet to be ported]
  • Uses MongoDB and moongodb client for python

TODO

  • Adding more wrapper for different use-cases.
  • Adding wrappers to fetch stale data from db.
  • Remove the dependency on constants.py(ugly). Ask user to provide it directly(For tests read from s specified file given as a command line argument).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages