Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (testpypi.python.org).
Help us improve Python packaging - Donate today!

Finds and displays tweets either in terminal on via web frontend

Project Description

Simple application for displaying tweets containing string given by parameter. In console mode application fetches desired number of tweets and then periodicaly checks for any new tweets. In web mode it runs a web frontend writen in Flask. Frontend is live at http://ggljzr.pythonanywhere.com.

Application was created as part of Python course (https://github.com/cvut/MI-PYT, in Czech).

Link to PyPI(testing) package: https://testpypi.python.org/pypi/pytwitter.

Requirements

  • Python3
  • click
  • requests
  • Flask

Installation

You can get this package directly from github:

::
git clone https://github.com/ggljzr/pytwitter cd pytwitter python3 setup.py install

Alternatively you can download package from testing PyPI link above. This is not recommended though, because it is not guaranteed that it will be there.

Usage

You need to have a Twitter account and create a new app at https://apps.twitter.com/. You will get key and secret which are used to generate token to access your Twitter account via API. For security purposes you may want to set this particular app to have read access only (since application just fetches tweets).

Then you need to create config.ini file containing Twitter API key and secret. Application looks for default config file in ~/.config/pytwitter/config.ini.

#create default directory for config
mkdir -p ~/.config/pytwitter/
#copy example config in place
cp config.ini.example ~/.config/pytwitter/config.ini

When you have config.ini in place, you just have to fill in API key and secret instead of placeholders.

[twitter]
key = your-api-key
secret = your-api-secret

[github]
#you can ignore this part

Alternatively you can use –config option to specify path to any custom config file (in web or console mode).

pytwitter web --config /path/to/your/config.ini

Console mode

#shows available options
pytwitter console --help
#starts fetching tweets containing '#python' in an infinte loop
#(quit with ctrl + c)
pytwitter console '#python'

Web mode

pytwitter web

Runs Flask embedded web server in debug mode. Web frontend will be available on localhost:5000. Note that this should be used only for debugging purposes. When deploying in production you should use webserver like nginx or Apache and gateway interface like wsgi to serve the app.

Frontend itself just displays tweets fetched by GET search/tweets Twitter API call. Query can be submitted via URL:

#fetches tweets with 'python' without retweets
http://localhost:5000/search/?query=python

#fetches tweets with 'python', with retweets
http://localhost:5000/search/?query=python&retweets=on

Tests

Application is distributed with a set of unit tests. You can run tests with following commands:

python3 setup.py test
#or if you have already installed pytest
pytest tests #note this is the only way to pass arguments to tests

Application package also contains set of recorded Betamax sessions, so you run test even without having registered Twitter account, or internet connection.

If you want to record your own sessions, you have to create a config.ini file, as described here and create AUTH_FILE environment variable:

export AUTH_FILE='/path/to/your/config.ini'

Then you call tests with pytest and --record option:

pytest tests --record

Test requirements

  • pytest
  • betamax

These should be collected automatically when running python3 setup.py test

Documentation

You can generate project documentation with Sphinx. First make sure it is installed:

#this only install Sphinx, since it is the only dependency
pip install -r docs/requirements.txt

Then you can run make to generate html docs or run doctests:

cd docs
make html #this will create html documentation in docs/_build/html
make doctest

To make sure Sphinx generate all documentation from docstrings correctly, you have to install the package (e.g. python3 setup.py install) first.

Release History

Release History

This version
History Node

0.5.0

History Node

0.4.1

History Node

0.4.0

History Node

0.3.3

History Node

0.3.2

History Node

0.3.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pytwitter-0.5.0.tar.gz (395.1 kB) Copy SHA256 Checksum SHA256 Source Nov 8, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting