Abhinav Sarkar 2008-07-10 14:04:42 +00:00
parent 305e49bc11
commit c04282b261
4 changed files with 117 additions and 48 deletions

View File

@ -132,10 +132,25 @@ class Api(object):
mbid = None):
return Artist.getInfo(self, artist, mbid)
def searchArtist(self,
artist,
limit = None,
page = None):
return Artist.search(self, artist, limit, page)
def getEvent(self, event):
return Event.getInfo(self, event)
def getLocation(self, name):
return Location(self, name)
def getCountry(self, name):
return Country(self, name)
def getGroup(self, name):
return Group(self, name)
def fetchUrl(self,
def _fetchUrl(self,
url,
parameters = None,
no_cache = False):
@ -184,7 +199,7 @@ class Api(object):
def fetchData(self, params):
params.update({'api_key': self.__apiKey})
xml = self.fetchUrl(Api.API_ROOT_URL, params)
xml = self._fetchUrl(Api.API_ROOT_URL, params)
data = ElementTree.XML(xml)
if data.get('status') != "ok":
@ -202,14 +217,14 @@ if sys.version.startswith('2.5'):
else:
import cElementTree as ElementTree
from error import LastfmError
from filecache import FileCache
from album import Album
from artist import Artist
from geo import Geo
from event import Event
from filecache import FileCache
#from group import Group
from geo import Location, Country
from group import Group
#from tag import Tag
#from track import Track
#from user import User
from error import LastfmError

View File

@ -15,7 +15,7 @@ class Artist(object):
streamable = None,
stats = None,
similar = None,
tags = None,
topTags = None,
bio = None):
self.__api = api
self.__name = name
@ -29,7 +29,7 @@ class Artist(object):
plays = stats.plays
)
self.__similar = similar
self.__tags = tags
self.__topTags = topTags
self.__bio = bio and Bio(
artist = self,
published = bio.published,
@ -52,14 +52,17 @@ class Artist(object):
def getStats(self):
return self.__stats
def getSimilar(self):
def getSimilar(self, limit = None):
if self.__similar:
return self.__similar
else:
pass
def getTags(self):
return self.__tags
def getTopTags(self):
if self.__topTags:
return self.__topTags
else:
pass
def getBio(self):
return self.__bio
@ -76,9 +79,28 @@ class Artist(object):
similar = property(getSimilar, None, None, "Similar's Docstring")
tags = property(getTags, None, None, "Tags's Docstring")
topTags = property(getTopTags, None, None, "Tags's Docstring")
bio = property(getBio, None, None, "Bio's Docstring")
def getEvents(self):
pass
def getTopAlbums(self):
pass
def getTopFans(self):
pass
def getTopTracks(self):
pass
@staticmethod
def search(api,
artist,
limit = None,
page = None):
pass
@staticmethod
def getInfo(api,

View File

@ -26,12 +26,7 @@ class Event(object):
self.__title = title
self.__artists = artists
self.__headliner = headliner
self.__venue = venue and Venue(
self,
name = venue.name,
location = venue.location,
url = venue.url
)
self.__venue = venue
self.__startDate = startDate
self.__startTime = startTime
self.__description = description
@ -118,12 +113,14 @@ class Event(object):
artists = [Artist(api, name = a.text) for a in data.findall('artists/artist')],
headliner = data.findtext('artists/headliner'),
venue = Venue(
event = int(data.findtext('id')),
name = data.findtext('venue/name'),
location = Location(
event = int(data.findtext('id')),
api,
city = data.findtext('venue/location/city'),
country = data.findtext('venue/location/country'),
country = Country(
api,
name = data.findtext('venue/location/country')
),
street = data.findtext('venue/location/street'),
postalCode = data.findtext('venue/location/postalcode'),
latitude = float(data.findtext(
@ -153,4 +150,4 @@ import time
from api import Api
from artist import Artist
from geo import Venue, Location
from geo import Venue, Location, Country

View File

@ -6,32 +6,28 @@ __license__ = "GNU Lesser General Public License"
class Geo(object):
"""A class representing an geographic location."""
pass
@staticmethod
def getEvents(api, location, distance, page):
pass
@staticmethod
def getTopArtists(api, country):
pass
@staticmethod
def getTopTracks(api, country):
pass
class Venue(object):
"""A class representing a venue of an event"""
def __init__(self,
event,
name = None,
location = None,
url = None):
self.__event = event
self.__name = name
self.__location = location and Location(
event,
city = location.city,
country = location.country,
street = location.street,
postalCode = location.postalCode,
latitude = location.latitude,
longitude = location.longitude,
timezone = location.timezone
)
self.__location = location
self.__url = url
def getEvent(self):
return self.__event
def getName(self):
return self.__name
@ -41,8 +37,6 @@ class Venue(object):
def getUrl(self):
return self.__url
event = property(getEvent, None, None, "Event's Docstring")
name = property(getName, None, None, "Name's Docstring")
location = property(getLocation, None, None, "Location's Docstring")
@ -57,7 +51,8 @@ class Location(object):
xmlns = "http://www.w3.org/2003/01/geo/wgs84_pos#"
def __init__(self,
event,
api,
name = None,
city = None,
country = None,
street = None,
@ -65,7 +60,8 @@ class Location(object):
latitude = None,
longitude = None,
timezone = None):
self.__event = event
self.__api = api
self.__name = name
self.__city = city
self.__country = country
self.__street = street
@ -73,9 +69,9 @@ class Location(object):
self.__latitude = latitude
self.__longitude = longitude
self.__timezone = timezone
def getEvent(self):
return self.__event
def getName(self):
return self.__city
def getCity(self):
return self.__city
@ -97,8 +93,8 @@ class Location(object):
def getTimezone(self):
return self.__timezone
event = property(getEvent, None, None, "Event's Docstring")
name = property(getName, None, None, "Name's Docstring")
city = property(getCity, None, None, "City's Docstring")
@ -114,5 +110,44 @@ class Location(object):
timezone = property(getTimezone, None, None, "Timezone's Docstring")
def getEvents(self,
distance = None,
page = None):
return Geo.getEvents(self.__api, self.name, distance, page)
events = property(getEvents, None, None, "Event's Docstring")
def __eq__(self, other):
return self.latitude == other.latitude and self.longitude == other.longitude
return self.latitude == other.latitude and self.longitude == other.longitude
class Country(object):
"""A class representing a country."""
def __init__(self,
api,
name = None):
self.__api = api
self.__name = name
def getName(self):
return self.__name
name = property(getName, None, None, "Name's Docstring")
def getTopArtists(self):
return Geo.getTopArtists(self.__api, self.name)
topArtists = property(getTopArtists, None, None, "Docstring")
topArtist = property(
lambda self: len(self.topArtists) and self.topArtists[0],
None, None, "Docstring"
)
def getTopTracks(self):
return Geo.getTopTracks(self.__api, self.name)
topTracks = property(getTopTracks, None, None, "Docstring")
topTrack = property(lambda self: len(self.topTracks) and self.topTracks[0],
None, None, "Docstring")
def __eq__(self, other):
return self.name == other.name