1
2
3 __author__ = "Abhinav Sarkar <abhinav@abhinavsarkar.net>"
4 __version__ = "0.2"
5 __license__ = "GNU Lesser General Public License"
6
7 from lastfm.base import LastfmBase
8 from lastfm.mixins import Cacheable, Searchable
9 from lastfm.lazylist import lazylist
10
11 -class Venue(LastfmBase, Cacheable, Searchable):
12 """A class representing a venue of an event"""
13 - def init(self,
14 api,
15 id = None,
16 name = None,
17 location = None,
18 url = None):
26
27 @property
29 """id of the venue"""
30 return self._id
31
32 @property
34 """name of the venue"""
35 return self._name
36
37 @property
39 """location of the event"""
40 return self._location
41
42 @property
44 """url of the event's page"""
45 return self._url
46
47 @LastfmBase.cached_property
56
59 params = self._default_params({'method': 'venue.getPastEvents'})
60 if limit is not None:
61 params.update({'limit': limit})
62
63 @lazylist
64 def gen(lst):
65 data = self._api._fetch_data(params).find('events')
66 total_pages = int(data.attrib['totalPages'])
67
68 @lazylist
69 def gen2(lst, data):
70 for e in data.findall('event'):
71 yield Event.create_from_data(self._api, e)
72
73 for e in gen2(data):
74 yield e
75
76 for page in xrange(2, total_pages+1):
77 params.update({'page': page})
78 data = self._api._fetch_data(params).find('events')
79 for e in gen2(data):
80 yield e
81 return gen()
82
83 @LastfmBase.cached_property
86
88 if not self.id:
89 raise InvalidParametersError("venue id has to be provided.")
90 params = {'venue': self.id}
91 params.update(extra_params)
92 return params
93
94 @staticmethod
96 return Venue(
97 api,
98 id = int(venue.findtext('id')),
99 name = venue.findtext('name'),
100 location = Location(
101 api,
102 city = venue.findtext('location/city'),
103 country = Country(
104 api,
105 name = venue.findtext('location/country')
106 ),
107 street = venue.findtext('location/street'),
108 postal_code = venue.findtext('location/postalcode'),
109 latitude = float(venue.findtext(
110 'location/{%s}point/{%s}lat' % ((Location.XMLNS,)*2)
111 )),
112 longitude = float(venue.findtext(
113 'location/{%s}point/{%s}long' % ((Location.XMLNS,)*2)
114 )),
115 ),
116 url = venue.findtext('url')
117 )
118
119 @staticmethod
121 try:
122 return hash(kwds['url'])
123 except KeyError:
124 raise InvalidParametersError("url has to be provided for hashing")
125
128
130 return self.url == other.url
131
134
137
138 from lastfm.api import Api
139 from lastfm.event import Event
140 from lastfm.geo import Location, Country
141 from lastfm.error import InvalidParametersError
142