Saltycrane logo

SaltyCrane Blog

Notes on Python, Django, and web development on Ubuntu Linux

    

How to use gnip-python to retrieve activity from Twitter, Delicious, Digg, etc.

  • Create an account at http://www.gnipcentral.com/
  • Download gnip-python from github.com.
  • Unpack it:
    $ tar -zxvf gnip-gnip-python-028364a70bd40dda0069ecdd3e7f6fff23bb985e.tar.gz
    
  • Move it to your example directory:
    $ mkdir ~/src/python/gnip-example
    $ mv gnip-gnip-python-028364a70bd40dda0069ecdd3e7f6fff23bb985e/*.py ~/src/python/gnip-example
  • Create an example file called ~/src/python/gnip-example/gnip-example.py:
    #!/usr/bin/env python
    
    from gnip import *
    
    gnip = Gnip("yourgniplogin@email.com", "yourpassword")
    
    for publisher in ["twitter", "digg", "delicious"]:
        activities = gnip.get_publisher_activities(publisher)
        print
        print publisher
        for activity in activities[:5]:
            print activity
    
  • Run it:
    $ python gnip-example.py

    And get the following results:
    twitter
    [derricklo, 2008-08-01T22:49:59+00:00, tweet, http://twitter.com/derricklo/statuses/875165550]
    [sam_metal, 2008-08-01T22:50:01+00:00, tweet, http://twitter.com/sam_metal/statuses/875165564]
    [lalatina, 2008-08-01T22:49:59+00:00, tweet, http://twitter.com/lalatina/statuses/875165544]
    [Nochipra, 2008-08-01T22:50:01+00:00, tweet, http://twitter.com/Nochipra/statuses/875165562]
    [jmcgaha, 2008-08-01T22:50:01+00:00, tweet, http://twitter.com/jmcgaha/statuses/875165556]
    
    digg
    [DAlexopoulos, 2008-08-01T18:50:08+00:00, submission, http://digg.com/health/CLA_Conjugated_Linoleic_Acid_Explained]
    [EradicateIV, 2008-08-01T18:50:05+00:00, submission, http://digg.com/pc_games/Pittco_Iron_Storm_9]
    [vivianpetman, 2008-08-01T18:49:58+00:00, submission, http://digg.com/business_finance/Dub_Me_Now_Turns_Business_Cards_into_Bits_and_Bytes_Small]
    [portia7896, 2008-08-01T18:49:53+00:00, submission, http://digg.com/world_news/Radioactive_water_yum]
    [hhdepot, 2008-08-01T18:49:52+00:00, submission, http://digg.com/2008_us_elections/Why_WE_are_democrats_in_2008_Original_Video]
    
    delicious
    [hanasama1, 2008-08-01T22:49:55+00:00, delicious, http://www.birchmere.com/]
    [Chrmftcotl, 2008-08-01T22:49:54+00:00, delicious, http://www.shaunlow.com/a-definitive-stumbleupon-guide-driving-traffic-to-websites/]
    [shankar, 2008-08-01T22:49:53+00:00, delicious, http://www.guardian.co.uk/books/2008/jul/26/salmanrushdie.bookerprize]
    [grzyweasel, 2008-08-01T22:49:53+00:00, delicious, http://patterntap.com/]
    [metaffect, 2008-08-01T22:50:05+00:00, delicious, http://dean.edwards.name/]
    Pretty cool.

This is just scratching the surface of what you can do with gnip. You can also filter by time or user. Or get XML output. Or you can publish to gnip yourself. See the gnip-python README for more python examples or the Gnip API for more detailed information. Also, here is a list of Gnip publishers.

If you get a ImportError: No module named iso8601 error, install iso8601.

Post a comment

Required
Required, but not displayed
Optional

Format using Markdown. (No HTML.)
  • Code blocks: prefix each line by at least 4 spaces or 1 tab (and a blank line before and after)
  • Code span: surround with backticks
  • Blockquotes: prefix lines to be quoted with >
  • Links: <URL>
  • Links w/ description: [description](URL)
Created with Django | Hosted by Slicehost