commit
71bef027c4
62
pylast.py
62
pylast.py
|
@ -18,7 +18,7 @@
|
|||
#
|
||||
# http://code.google.com/p/pylast/
|
||||
|
||||
__version__ = '0.5'
|
||||
__version__ = '0.6'
|
||||
__author__ = 'Amr Hassan'
|
||||
__copyright__ = "Copyright (C) 2008-2010 Amr Hassan"
|
||||
__license__ = "apache2"
|
||||
|
@ -1735,7 +1735,7 @@ class Event(_BaseObject):
|
|||
v = doc.getElementsByTagName("venue")[0]
|
||||
venue_id = _number(_extract(v, "id"))
|
||||
|
||||
return Venue(venue_id, self.network)
|
||||
return Venue(venue_id, self.network, venue_element=v)
|
||||
|
||||
def get_start_date(self):
|
||||
"""Returns the date when the event starts."""
|
||||
|
@ -3474,13 +3474,25 @@ class Venue(_BaseObject):
|
|||
"""A venue where events are held."""
|
||||
|
||||
# TODO: waiting for a venue.getInfo web service to use.
|
||||
# TODO: As an intermediate use case, can pass the venue DOM element when using
|
||||
# Event.get_venue() to populate the venue info, if the venue.getInfo API
|
||||
# call becomes available this workaround should be removed
|
||||
|
||||
id = None
|
||||
info = None
|
||||
name = None
|
||||
location = None
|
||||
url = None
|
||||
|
||||
def __init__(self, id, network):
|
||||
def __init__(self, id, network, venue_element=None):
|
||||
_BaseObject.__init__(self, network)
|
||||
|
||||
self.id = _number(id)
|
||||
if venue_element is not None:
|
||||
self.info = _extract_element_tree(venue_element)
|
||||
self.name = self.info.get('name')
|
||||
self.url = self.info.get('url')
|
||||
self.location = self.info.get('location')
|
||||
|
||||
def __repr__(self):
|
||||
return "pylast.Venue(%s, %s)" %(repr(self.id), repr(self.network))
|
||||
|
@ -3500,6 +3512,21 @@ class Venue(_BaseObject):
|
|||
|
||||
return self.id
|
||||
|
||||
def get_name(self):
|
||||
"""Returns the name of the venue."""
|
||||
|
||||
return self.name
|
||||
|
||||
def get_url(self):
|
||||
"""Returns the URL of the venue page."""
|
||||
|
||||
return self.url
|
||||
|
||||
def get_location(self):
|
||||
"""Returns the location of the venue (dictionary)."""
|
||||
|
||||
return self.location
|
||||
|
||||
def get_upcoming_events(self):
|
||||
"""Returns the upcoming events in this venue."""
|
||||
|
||||
|
@ -3613,6 +3640,35 @@ def _extract(node, name, index = 0):
|
|||
else:
|
||||
return None
|
||||
|
||||
def _extract_element_tree(node, index = 0):
|
||||
"""Extract an element tree into a multi-level dictionary
|
||||
|
||||
NB: If any elements have text nodes as well as nested
|
||||
elements this will ignore the text nodes"""
|
||||
|
||||
def _recurse_build_tree(rootNode, targetDict):
|
||||
"""Recursively build a multi-level dict"""
|
||||
|
||||
def _has_child_elements(rootNode):
|
||||
"""Check if an element has any nested (child) elements"""
|
||||
|
||||
for node in rootNode.childNodes:
|
||||
if node.nodeType == node.ELEMENT_NODE:
|
||||
return True
|
||||
return False
|
||||
|
||||
for node in rootNode.childNodes:
|
||||
if node.nodeType == node.ELEMENT_NODE:
|
||||
if _has_child_elements(node):
|
||||
targetDict[node.tagName] = {}
|
||||
_recurse_build_tree(node, targetDict[node.tagName])
|
||||
else:
|
||||
val = None if node.firstChild is None else _unescape_htmlentity(node.firstChild.data.strip())
|
||||
targetDict[node.tagName] = val
|
||||
return targetDict
|
||||
|
||||
return _recurse_build_tree(node, {})
|
||||
|
||||
def _extract_all(node, name, limit_count = None):
|
||||
"""Extracts all the values from the xml string. returning a list."""
|
||||
|
||||
|
|
4
setup.py
4
setup.py
|
@ -22,11 +22,11 @@ def get_build():
|
|||
return str(build)
|
||||
|
||||
setup(name = "pylast",
|
||||
version = "0.1+0.5." + get_build(),
|
||||
version = "0.6." + get_build(),
|
||||
author = "Amr Hassan <amr.hassan@gmail.com>",
|
||||
description = "A Python interface to Last.fm (and other API compatible social networks)",
|
||||
author_email = "amr.hassan@gmail.com",
|
||||
url = "https://github.com/Elizacat/",
|
||||
url = "https://github.com/inversion/",
|
||||
py_modules = ("pylast",),
|
||||
license = "Apache2"
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue