def handle_resp(resp):
	for track_data in resp:
		try:
			track = Track.objects.get(shortname=track_data.get('shortname'))
		except ObjectDoesNotExist:
			try:
				artist = Artist.objects.get(name=track_data.get('artist_tr'))
			except ObjectDoesNotExist:
				artist = Artist(name=track_data.get('artist_tr'))
				artist.save()
			finally:
				track = Track(name = track_data.get('name'),
					artist = artist,
					cover = True if track_data.get('cover') == 't' else False,
					decade = track_data.get('decade'),
					difficulty_band = track_data.get('difficulty_band'),
					difficulty_bass = track_data.get('difficulty_bass'),
					difficulty_drums = track_data.get('difficulty_drums'),
					difficulty_guitar = track_data.get('difficulty_guitar'),
					difficulty_keys = track_data.get('difficulty_keys'),
					difficulty_pro_bass = track_data.get('difficulty_pro_bass'),
					difficulty_pro_drums = track_data.get('difficulty_pro_drums'),
					difficulty_pro_guitar = track_data.get('difficulty_pro_guitar'),
					difficulty_pro_keys = track_data.get('difficulty_pro_keys'),
					difficulty_vocals = track_data.get('difficulty_vocals'),
					genre_symbol = track_data.get('genre_symbol'),
					rating = track_data.get('rating'),
					source = track_data.get('source'),
					vocal_parts = track_data.get('vocal_parts'),
					year_released = track_data.get('year_released'),
					shortname = track_data.get('shortname'),
					)
				track.save()
Example #2
0
def make_artist(user,artist):
	'''user is a UserProfile object,
	artist is the json object returned by lastfm, of the following format:
	{u'image': [{u'#text': u'http://userserve-ak.last.fm/serve/34/9269.jpg',
             u'size': u'small'},
            {u'#text': u'http://userserve-ak.last.fm/serve/64/9269.jpg',
             u'size': u'medium'},
            {u'#text': u'http://userserve-ak.last.fm/serve/126/9269.jpg',
             u'size': u'large'},
            {u'#text': u'http://userserve-ak.last.fm/serve/252/9269.jpg',
             u'size': u'extralarge'},
            {u'#text': u'http://userserve-ak.last.fm/serve/500/9269/Ratatat.jpg',
             u'size': u'mega'}],
	 u'mbid': u'f467181e-d5e0-4285-b47e-e853dcc89ee7',
	 u'name': u'Ratatat',
	 u'playcount': u'780',
	 u'streamable': u'1',
	 u'tagcount': u'0',
	 u'url': u'http://www.last.fm/music/Ratatat'}
	 '''
	try:
		print artist.get('name')
	except:
		print 'error!'
	try:
		a = Artist.objects.get(name=artist.get('name'))
	except ObjectDoesNotExist:
		a = Artist(name=artist.get('name'))
		a.save()
	try:
		relation = UserArtist.objects.get(useraccount=user, artist=a)
	except ObjectDoesNotExist:
		relation = UserArtist(useraccount=user, artist=a)
	relation.listens = int(artist.get('playcount')) 
	relation.save()
def make_artist(user, artist):
    '''user is a UserProfile object,
	artist is the json object returned by lastfm, of the following format:
	{u'image': [{u'#text': u'http://userserve-ak.last.fm/serve/34/9269.jpg',
             u'size': u'small'},
            {u'#text': u'http://userserve-ak.last.fm/serve/64/9269.jpg',
             u'size': u'medium'},
            {u'#text': u'http://userserve-ak.last.fm/serve/126/9269.jpg',
             u'size': u'large'},
            {u'#text': u'http://userserve-ak.last.fm/serve/252/9269.jpg',
             u'size': u'extralarge'},
            {u'#text': u'http://userserve-ak.last.fm/serve/500/9269/Ratatat.jpg',
             u'size': u'mega'}],
	 u'mbid': u'f467181e-d5e0-4285-b47e-e853dcc89ee7',
	 u'name': u'Ratatat',
	 u'playcount': u'780',
	 u'streamable': u'1',
	 u'tagcount': u'0',
	 u'url': u'http://www.last.fm/music/Ratatat'}
	 '''
    try:
        print artist.get('name')
    except:
        print 'error!'
    try:
        a = Artist.objects.get(name=artist.get('name'))
    except ObjectDoesNotExist:
        a = Artist(name=artist.get('name'))
        a.save()
    try:
        relation = UserArtist.objects.get(useraccount=user, artist=a)
    except ObjectDoesNotExist:
        relation = UserArtist(useraccount=user, artist=a)
    relation.listens = int(artist.get('playcount'))
    relation.save()