PyTwitService

Overview

PyTwitService was originally designed to help with the administration of the @OlympicTrucks twitter account. PyTwitService parses a user’s timeline (i.e. tweets of all followers), searches for certain keywords, and RT’s the specific tweet if the tweet’s contents matches the expected criteria. This is run from a host computer and utilizes the Twitter REST API v.1.1 and utilizes OAuth for authentication.

Download

https://bitbucket.org/drocpdp/pytwitservice

Dependencies and Setup

Dependencies

  • python-twitter — https://code.google.com/p/python-twitter/
  • simplejson — http://cheeseshop.python.org/pypi/simplejson
  • httplib2 — http://code.google.com/p/httplib2/
  • python-oauth2 — http://github.com/simplegeo/python-oauth2

To install python-twitter, install simplejson, httplib2, and python-oauth2. Then, install python-twitter from source.

Setup and Config

Twitter Application

You will need the following:

  • Twitter Account (one that you wish to parse)
  • Twitter Application (to access your Twitter Account)
  • Consumer Key
  • Consumer Secret
  • Access Token Key
  • Access Token Secret

There are several tutorials online on how to obtain these.

See:

  • http://stackideas.com/docs/easyblog/autoposting/creating-your-first-twitter-application.html
  • http://net.tutsplus.com/tutorials/php/creating-a-twitter-oauth-application/

You can also utilize get_access_token.py located in your python-twitter source (python-twitter/get_access_token.py)

locations.properties

In your PyTwitService source, navigate to ../PyTwitService/config/locations.properties

consumer_key_location

This should be set to the location of the text file containing the consumer key value

consumer_secret_location

This should be set to the location of the text file containing the consumer secret value

access_token_key_location

This should be set to the location of the text file containing the access token value

access_token_secret_location

This should be set to the location of the text file containing the access token secret value

since_tweet_id, max_tweet_id, temp_max_tweet_id

These should be set to the locations of text files that will hold a tweet id. The directory should exist. The files themselves need not exist, but feel free to “touch” them to create a blank file.

filters_location

This should be set to the location of the text files containing the user-set filters used to single out certain tweets in your timeline.

pytwitservice.properties

In your PyTwitService source, navigate to ../PyTwitService/config/pytwitservice.properties

email_config_file

This should be set to point to your email config properties file.

Email Config Properties File

The location and name of this file is set in your pytwitservice.properties file.

[default]

This is a “section” (see http://docs.python.org/2/library/configparser.html). This should be set to [default]

from

Set this to your “From” email address

to

Set this to your subscribers (who you are sending email to.) Separate by comma.

to_admin

This is not used as of v.1.0.0

password

The password of your “From” email address.