Index of /python/pyupcoming
Name Last modified Size Description
Parent Directory -
pyupcoming-0.1.tar.gz 2008-11-22 09:33 4.1K GZIP compressed docume>
Changes 2008-11-22 09:33 1.1K
NAME
pyupcoming - Simple Python interface to the Upcoming.org REST API
SYNOPSIS
from pyupcoming import pyupcoming
from ConfigParser import SafeConfigParser
from os.path import expanduser
cfg = SafeConfigParser();
cfg.read(os.path.expanduser("~/.upcoming/upcoming.conf"))
py = pyupcoming(cfg)
xp = py.execute_method("watchlist.getList")
for e in xp.findnodes("/rsp/watchlist[@status='watch']") :
print e.attrib['event_id']
# The same but different :
for id in xp.findnodes("/rsp/watchlist[@status='watch']/@event_id") :
print id
DESCRIPTION
pyupcoming is a simple Python interface to the Upcoming.org REST API.
It does not auto-create methods for the API or try to render the data
returned by Upcoming into any kind of Pythonic model.
It does allow you to query the results of an API call using XPath. Sort
of.
Sort of, in the sense that you can query stuff using XPath but you'll
get back an elementtree object rather than a proper XML-ish object with
its own DOM functionality.
I could have used libxml but that introduces a whole other world of
dependencies. I wanted a library that could easily run on a variety of
platforms with Python support. I started out with another more Pythonic
interface to the Upcoming API and then spent most of a morning trying to
shoehorn in features that I needed before getting lost in a twisty maze
of *__getattr__* functions and giving up.
So, this is the 80. Patches for the remaining 20 are welcome.
pyupcoming PACKAGE METHODS
pyupcoming(SafeConfigParser=None)
If no config object is passed, the (pyupcoming) object constructor will
look for a config in the current user's home directory in a subdirectory
named .upcoming. The config itself should be name upcoming.conf.
Config options are orgranized by "block". pyupcoming options are grouped
in a pyupcoming block. Valid options are :
* api_key
String. *required*
A valid Upcoming.org API key.
* auth_token
String.
Required for method calls with restricted access.
* always_auth
Boolean.
Inidicates whether method calls should always be called passing the
auth_token.
Returns a *pyupcoming* object.
pyupcoming OBJECT METHODS
obj.execute_method(str_method, **kwargs)
*str_method* is the name of the Upcoming.org API method.
*kwargs* are any arguments passed to the method. Please consult the
Upcoming.org API documents for details.
Returns a *pyupcomingResult* object on success, or raises a
*pyupcomingError* exception if there was a problem.
pyupcomingResult OBJECT METHODS
obj.findnodes(str_xpath)
Returns a list of strings or elementtree *Element* objects corresponding
to the XPath query passed.
obj.as_string()
Returns a, drumroll, string representing the raw XML returned by the API
call.
pyupcomingError OBJECT METHODS
obj.code()
Returns an int.
obj.reason()
Returns a string.
EXAMPLES
Config file
[pyupcoming]
auth_token=h893yiusdjhzcghjasiu78937656qwe67765xzgh
api_key=3674562946563
always_auth=1
Printing your watchlist
def main () :
py = pyupcoming()
wl = py.execute_method("watchlist.getList")
for watch in wl.findnodes("/rsp/watchlist") :
eid = watch.attrib['event_id']
ev = py.execute_method("event.getInfo",
event_id=eid)
vid = ev.findnodes("/rsp/event/@venue_id")[0]
vn = py.execute_method("venue.getInfo",
venue_id=vid)
print serialize_event(ev.findnodes("/rsp/event")[0],
vn.findnodes("/rsp/venue")[0])
def serialize_event (event, venue) :
return u"@prefix : <x-urn:upcoming#> .\n\n" + \
u"<x-urn:upcoming:event#%s>\n" % event.attrib['id'] + \
u" :event \"%s\";\n" % event.attrib['name'] + \
u" :datetime \"%sT%s\";\n" % (event.attrib['start_date'], event.attrib['start_time']) + \
u" :venue \"%s\";\n" % venue.attrib['name'] + \
u" :address \"%s\";\n" % venue.attrib['address'] + \
u" :phone \"%s\";\n" % venue.attrib['phone'] + \
u" ."
if __name__ == "__main__" :
main()
VERSION
0.1
DATE
$Date: 2006/01/28 23:55:30 $
AUTHOR
Aaron Straup Cope
REQUIREMENTS
* elementtree
<http://effbot.org/downloads/#elementtree>
* PDIS XPath
<http://pdis.hiit.fi/pdis/download/>
SEE ALSO
<http://upcoming.org/services/api/>
LICENSE
Copyright (c) 2006 Aaron Straup Cope. All Rights Reserved.
This is free software. You can redistribute it and/or modify it under
the same terms as Perl Artistic License itself.