1. Lucas Taylor
  2. txCollecta

Source

txCollecta /

Filename Size Date modified Message
docs
examples
txcollecta
1.1 KB
2.1 KB
1.0 KB
DOCUMENTATION
=============

Documentation is located in the /docs directory
txCollecta/docs/html/index.html

To build the Sphinx docs from txCollecta/docs/src/

$ make html


REQUIREMENTS
============

Python >= 2.5: http://www.python.org/
Twisted:       http://www.twistedmatrix.com/
feedparser:    http://www.feedparser.org/
simplejson (Python <=2.5):  http://www.undefined.org/python/

To build docs:
Sphinx:        http://sphinx.pocoo.org/
Pygments:      http://pygments.org/


TODO
====
The current client implements most of the Collecta HTTP API.
See TODO for details.


TESTS
=====
$ trial txcollecta.tests


USAGE
=====

A simple usage example:


from txcollecta.client import CollectaClient

API_KEY = '12345678901234567890'
c = CollectaClient(API_KEY)

# Unparsed results
result = c.search('"Sports Team"')
def parseAtom(result):
    # diy Atom parsing goes here
    print result # punt!
result.addCallback(parseAtom).addErrback(log.err)

# Parsed dict-like object returned from feedparser
parsed = c.getParsed('"meaningless gossip"')
def processParsed(result):
    print result
parsed.addCallback(processParsed)

# Shortcuts exist for specifying desired categories (Stories, Comments, Updates, Photos, Videos)
stories = c.getStories(query='Individual Search Terms OR "Search Term"')
def processStories(result):
    for story in result.stories:
        print story.title, story.links
stories.addCallback(processStories)

photos = c.getPhotos(query='"attractive individuals"')
def processPhotos(result):
    # naive demo; may destroy everything!
    for idx, photo in enumerate(result.photos.enclosures):
        fname = path.basename(urlparse(photo.href).path)
        d = twisted.web.client.downloadPage(photo.href, fname)
        # Add callback/errback for when file is downloaded and saved to disk
        d.addCallback(lambda _: pass)
        d.addErrback(log.err)
photos.addCallback(processPhotos).addErrback(log.err)



CREDIT
======
Testing strategy and some structural ideas came from reviewing the txspore library:
https://launchpad.net/txspore