Allow getting venue info through Event.get_venue() as a workaround until the Venue.getInfo API call is added to Last.fm
This commit is contained in:
parent
78aac5c437
commit
88f5b5e6b9
60
pylast.py
60
pylast.py
|
@ -1735,7 +1735,7 @@ class Event(_BaseObject):
|
||||||
v = doc.getElementsByTagName("venue")[0]
|
v = doc.getElementsByTagName("venue")[0]
|
||||||
venue_id = _number(_extract(v, "id"))
|
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):
|
def get_start_date(self):
|
||||||
"""Returns the date when the event starts."""
|
"""Returns the date when the event starts."""
|
||||||
|
@ -3459,13 +3459,25 @@ class Venue(_BaseObject):
|
||||||
"""A venue where events are held."""
|
"""A venue where events are held."""
|
||||||
|
|
||||||
# TODO: waiting for a venue.getInfo web service to use.
|
# 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
|
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)
|
_BaseObject.__init__(self, network)
|
||||||
|
|
||||||
self.id = _number(id)
|
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):
|
def __repr__(self):
|
||||||
return "pylast.Venue(%s, %s)" %(repr(self.id), repr(self.network))
|
return "pylast.Venue(%s, %s)" %(repr(self.id), repr(self.network))
|
||||||
|
@ -3485,6 +3497,21 @@ class Venue(_BaseObject):
|
||||||
|
|
||||||
return self.id
|
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):
|
def get_upcoming_events(self):
|
||||||
"""Returns the upcoming events in this venue."""
|
"""Returns the upcoming events in this venue."""
|
||||||
|
|
||||||
|
@ -3598,6 +3625,35 @@ def _extract(node, name, index = 0):
|
||||||
else:
|
else:
|
||||||
return None
|
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:
|
||||||
|
targetDict[node.tagName] = _unescape_htmlentity(node.firstChild.data.strip())
|
||||||
|
|
||||||
|
return targetDict
|
||||||
|
|
||||||
|
return _recurse_build_tree(node, {})
|
||||||
|
|
||||||
def _extract_all(node, name, limit_count = None):
|
def _extract_all(node, name, limit_count = None):
|
||||||
"""Extracts all the values from the xml string. returning a list."""
|
"""Extracts all the values from the xml string. returning a list."""
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue