GithubHelp home page GithubHelp logo

deepakkoli93 / mini-twitter-api-client Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 21 KB

A simple twitter api client in python

Home Page: https://mini-twitter-client.herokuapp.com/

Python 76.76% HTML 23.24%
python twitter-api

mini-twitter-api-client's Introduction

A mini twitter api client

This is a python implementation of a twitter api client which can fetch tweets based on :

  1. a hashtag present in the tweet, and
  2. the number of times the tweet has been retweeted

Usage

Make sure to have python 2.7.x installed

Clone the repo using

git clone https://github.com/Deepakkoli93/mini-twitter-api-client.git

Install the dependencies

pip install -r requirements.txt

If the above does not work then install the requests module using

pip install requests

Edit the configuration.ini file to place your twitter app's consumer key and consumer secret. I have provided a sample key and secret so you can leave the configuration.ini as it is.

To get tweets with hashtag #custserv and atleast one retweet run:

python sample.py

General usage

Go to the repo's root directory and open a python shell. To fetch tweets, run the following commands

from TwitterApiClient.api_client import api_client
api_client = api_client()
api_client.display_tweets("#custserv", 1)

This will fetch and disaply the tweets which have #custserv hashtag present in them and have been retweeted at least once.

display_tweets can accept two optional parameters. As shown in the above example, the minimum number of retweets required is 1 but that parameter can be skipped, it defaults to 1

It can take another parameter which is a file name (defaults to "tweets.txt"). The client will only print the text part of the tweets on the terminal and a complete dump of the tweets with all their fields will be written to "tweets.txt" (or a filename if provided). The following example fetches tweets which have #custserv hashtag in them and have atleast 100 retweets. The complete details of these tweets will then be written into popular_tweets.txt

api_client.display_tweets("#ipl", 100, "popular_tweets.txt")

The module contains the following basic function:

  • _fetch_bearer_token - fetches the authentication bearer token required to authenticate other api calls and saves it
  • _fetch_tweets - uses the bearer token to make a call to twitter's search api to fetch the tweets containg the required hashtag. It then filters those tweets according to the minimum number of tweets required and returns them
  • display_tweets - This is the function that the user calls. It uses _fetch_tweets to get the required tweets. Then it displays them on the terminal and writes them to a file.

UI

The app is available at https://mini-twitter-client.herokuapp.com/ Flask is used to map routes to python methods and jinja is used to create templates. This is a one page app with a form to enter hashtag and minimum retweets required To serve locally, set the variable PORT by running

export PORT=1234

then run

python run.py

The app will now be live at http://localhost:1234/

Tests

Python unittest is used to test the methods of the TwitterApiClient module. The tests can be run from the project's source directory as follows

python tests/run_tests.py

mini-twitter-api-client's People

Contributors

deepakkoli93 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

adi0010

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.