def getConcertsForArtist(self, **kwargs): """ Returns a map of date->concert for the given artist between the given dates. Keyword Arguments: minDate -- minimum date to request (required) maxDate -- maximum date to request (required) """ # Build the request artistPathTerm = ('mbid:' + self.mbid) if (self.mbid is not None) else self.songkickid requestUrl = 'http://api.songkick.com/api/3.0/artists/%s/calendar.json' % artistPathTerm requestParams = { 'apikey': Constants.songKickApiKey, 'min_date': kwargs.get('minDate'), 'max_date': kwargs.get('maxDate') } # Retrieve and parse the response response = CacheHelpers.retrieveRequestJson(requestUrl, requestParams) # print response.url json = response['resultsPage'] if json['status'] != 'ok': return None concerts = {} if json['totalEntries'] == 0: return concerts # Go over each event and add it to the concerts list for event in json['results']['event']: locObj = event['location'] venueObj = event['venue'] venueInfo = VenueInformation(locObj['lat'], locObj['lng'], locObj['city'], venueObj['displayName'], venueObj['id']) eventDate = parser.parse(event['start']['date']).date() eventInfo = EventInformation(eventDate, venueInfo) concerts[eventDate] = eventInfo return concerts
def executeSearch(self): # Build the request requestUrl = 'http://api.songkick.com/api/3.0/search/artists.json' requestParams = { 'apikey': Constants.songKickApiKey, 'query': self.searchString, 'per_page': Constants.artistSearchResultNumber } # Retrieve and parse the response response = CacheHelpers.retrieveRequestJson(requestUrl, requestParams) searchResults = response['resultsPage'] if searchResults['status'] != 'ok': return None results = [] if searchResults['totalEntries'] == 0: return results for result in searchResults['results']['artist']: mbid = None if result['identifier'] != []: # TODO: Always take the first element? mbid = result['identifier'][0]['mbid'] results.append(ArtistSearchResult(result['displayName'], result['id'])) return results