Get a Venue's name

52 views
Skip to first unread message

evilgnome

unread,
Jun 18, 2010, 6:02:03 PM6/18/10
to pylast
Hi all. I'm working on a program that uses pylast (thanks!). I can get
Venue objects for upcoming events, but how can I get the name of the
venue from it?

Thanks for any help,
Andy

NVSBL monster

unread,
Jun 18, 2010, 9:15:12 PM6/18/10
to pylast
>>> import pylast

#
# all the usual jazz resulting in a Network object
#

>>> user = network.get_user("your username")
>>> events = user.get_upcoming_events()
>>> events[0].get_venue()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 1655,
in get_venue
doc = self._request("event.getInfo", True)
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 969,
in _request
return _Request(self.network, method_name,
params).execute(cacheable)
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 812,
in execute
response = self._download_response()
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 803,
in _download_response
self._check_response_for_errors(response_text)
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 826,
in _check_response_for_errors
raise WSError(self.network, status, details)
pylast.WSError: Invalid event id supplied

Hmm.. this isn't right. Iunno if I'm doing something wrong, or the
pylast library is slightly effed, but what should have worked clearly
didn't.
Luckily, there is another way.

>>> import urllib

>>> user = "YOUR USERNAME HERE"
>>> api_key = "YOUR API KEY HERE"
>>> url = "http://ws.audioscrobbler.com/2.0/?method=user.getevents&user=%s&api_key=%s" % (user, api_key)
>>> events = urllib.urlopen(url).read()

events is a string, which contains a standard XML-formatted response
to the method call contained in url. From this, you can extract the
information you seek, including the venue names of all the upcoming
concerts. I'm sure the pylast method is easier, but for at least me,
running the latest version of pylast, it doesn't.

NVSBL monster

unread,
Jun 19, 2010, 4:30:00 AM6/19/10
to pylast
Here's the API doc page for the user.getEvents method on Last.fm:
http://www.last.fm/api/show?service=291
Forgot to include this in my first post.
> >>> url = "http://ws.audioscrobbler.com/2.0/?method=user.getevents&user=%s&api_k..." % (user, api_key)

evilgnome

unread,
Jun 21, 2010, 12:10:05 AM6/21/10
to pylast
Thanks for that. There is probably a similar last.fm API call to do
the same for an artist's events (as opposed to a user's), which is
what I'm looking for. I haven't looked into the direct last.fm API at
all yet, I was hoping I could just use pylast for this, but maybe I'll
poke around.

On Jun 18, 9:15 pm, NVSBL monster <nvsbl.mon...@gmail.com> wrote:
> >>> url = "http://ws.audioscrobbler.com/2.0/?method=user.getevents&user=%s&api_k..." % (user, api_key)

evilgnome

unread,
Jun 30, 2010, 12:58:46 PM6/30/10
to pylast
In case anyone else is interested, this is the code I now use to get
venue information from a pylast Event object (thanks to NVSBL
monster):

def get_venue_name(self, event):
event_id = str(event.get_id())
url = 'http://ws.audioscrobbler.com/2.0/?
method=event.getinfo&event='
url += event_id
url += '&api_key='
url += self.api_key
event_xml = urllib.urlopen(url).read()

pre, post = '<name>', '</name>'
regex = re.compile(pre + '.*' + post)
match = regex.search(event_xml).group()
name = match[len(pre) : 0 - len(post)]

pre, post = '<city>', '</city>'
regex = re.compile(pre + '.*' + post)
match = regex.search(event_xml).group()
city = match[len(pre) : 0 - len(post)]

pre, post = '<country>', '</country>'
regex = re.compile(pre + '.*' + post)
match = regex.search(event_xml).group()
country = match[len(pre) : 0 - len(post)]

return ', '.join([name, city, country])
Reply all
Reply to author
Forward
0 new messages