This commit is contained in:
hugovk 2014-02-26 13:16:28 +02:00
parent eadce48315
commit b48f56badf
2 changed files with 67 additions and 123 deletions

View file

@ -18,7 +18,7 @@
#
# http://code.google.com/p/pylast/
__version__ = '0.6'
__version__ = '0.5'
__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, venue_element=v)
return Venue(venue_id, self.network)
def get_start_date(self):
"""Returns the date when the event starts."""
@ -1976,7 +1976,7 @@ class Library(_BaseObject):
"""Add an album to this library."""
params = self._get_params()
params["artist"] = album.get_artist.get_name()
params["artist"] = album.get_artist().get_name()
params["album"] = album.get_name()
self._request("library.addAlbum", False, params)
@ -3459,25 +3459,13 @@ 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, venue_element=None):
def __init__(self, id, network):
_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))
@ -3497,21 +3485,6 @@ 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."""
@ -3625,35 +3598,6 @@ 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."""

View file

@ -22,11 +22,11 @@ def get_build():
return str(build)
setup(name = "pylast",
version = "0.6." + get_build(),
version = "0.1+0.5." + 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/inversion/",
url = "https://github.com/Elizacat/",
py_modules = ("pylast",),
license = "Apache2"
)