Books, Cats, Tech

"Everything that moves serves to interest and amuse a cat." — F.A. Paradis Moncrif

Vicki Brown

My home on the WWW
Est: 1994

Email: vlb@cfcl.com
Home

More About Me

Lifestream

Building a Twitter Reader

Using pyTwerp and TWiki

Reference: the pyTwerp man page

The whole concept of Twerp is to allow your Twitter data stream to be pulled from Twitter, formatted via a template you can control and then output to the console.

It also allows you to post a status message or send a direct message.

That's it in a nutshell.

You can access the following data streams on Twitter:

  • Friends Timeline
  • Your Timeline
  • Your Replies
  • Direct Messages sent to you
Options:
    -c  --config    <filename>  Location of the configuration file.
                                The default file ~/.twerp.cfg is created
                                and populated the first time you run Twerp.
    -U  --username  <name>      Twitter User ID - needed only the first time
                                you run Twerp as Twerp will save the value.
    -P  --password  <password>  Twitter Password - also only needed once.
    -T  --template  <text>      Template string.  This string is used to
                                format the data received from Twitter.
                                Details on the format can be found below.
    -s  --since     <date>      Date used by Twerp when pulling data from Twitter.
    -d  --direct    <message>   Send a direct message.
    -t  --timeline              Twerp will ouput your timeline.
    -f  --friends               Twerp will output your friend's timeline.
    -r  --replies               Twerp will output replies to you.
    -p  --public                Twerp will output the public timeline.

Examples:

    twerp -U bear -P sekrit -f
    twerp -frp
    twerp status message to post
    twerp -d decklin direct message to decklin
    twerp -f --since "Wed, 01 Aug 2007 05:39:42 GMT"

Template Format

If you are familiar with how Python specifies the format string then you know exactly how this works :)

Each post coming from Twitter has the following parts:

    Field                   Template
    user_id                 %(user_id)s
    user_name               %(user_name)s
    user_screen_name        %(user_screen_name)s
    user_description        %(user_description)s
    user_location           %(user_location)s
    user_protected          %(user_protected)s
    user_url                %(user_url)s
    user_profile_image_url  %(user_profile_image_url)s
    id                      %(id)s
    text                    %(text)s
    source                  %(source)s
    created_at              %(created_at)s

The parts of each post is stored in a dictionary and then passed to Python as the formatted data source. To reference the parts, place a field reference in your template string.

The default template string is:

%(user_screen_name)s: %(text)s