def get_artist(): artist_name = request.args.get('artist') if artist_name: artist = cache.get('artist:%s' % artist_name) if artist is None: artist = lastfm.get_artist(artist_name) cache.set('artist:%s' % artist_name, artist, timeout=5*60) return json_response(artist) else: return json_response({})
def detail(artist_name): itunes_search = itunes.search(artist_name, limit=1) if len(itunes_search): itunes_data = itunes.lookup(itunes_search[0]['artistId']) lastfm_data = lastfm.get_artist(itunes_data['artistName']) song_fields = ['trackName', 'previewUrl', 'artworkUrl100', 'collectionName', 'trackPrice', 'collectionViewUrl'] itunes_songs = itunes.search(itunes_data['artistName'])[:3] itunes_songs = [dict((k, song[k]) for k in song_fields if k in song) for song in itunes_songs] return render_template('detail.html', **{ 'name': itunes_data['artistName'], 'picture': lastfm_data['image'][2]['#text'], 'on_tour': True, 'other_songs': itunes_songs, 'description': ', '.join(tag['name'] for tag in lastfm_data['tags']['tag'][:3]), })
def import_events(filepath, hashtag=u"#SXSWm #Showcase", location=u'austin', venue_city='Austin', venue_state='TX', venue_zip=u'', event_source='sxsw', geoloc="30.27,-97.74", **kwargs): from artist.models import ArtistProfile from event.models import Event, Venue from lastfm import get_artist from lastfm.fetch_events import get_raw_image _ARTIST = ArtistProfile.objects.get(url='riotvine-member') _DATE_FORMAT = "%m/%d/%Y" # format: 03/17/2010 f = open(filepath, 'r') lines = f.readlines() max = len(lines) rnum = 0 while True: if rnum >= max: break r = lines[rnum].strip().split('|') print rnum, r if r[1] == u'' and r[2] == u'' and r[3] == u'' and r[4] == u'': # venue row #1 if rnum + 1 >= max: break r2 = lines[rnum+1].strip().split('|') if r2[1] == u'' and r2[2] == u'' and r2[3] == u'' and r2[4] == u'': # venue row #2 venue = r[0] venue_address = r2[0].split(')\xc2\xa0(')[0][1:].decode('utf-8') querystring = urlencode({'q':u'%s %s, %s %s' % (venue[:25], venue_address, venue_city, venue_state)}) map_url = u'http://maps.google.com/?%s' % querystring vn, created = Venue.objects.get_or_create( name=venue[:255], geo_loc=geoloc, defaults=dict( source='user-entered', address=venue_address[:255], city=venue_city[:255], state=venue_state, zip_code=venue_zip[:12], venue_url=u'', map_url=map_url, ) ) rnum += 1 # skip this row next time around else: # event row artist_name = r[1] artist_dictionary = get_artist(artist_name) bio = artist_dictionary.get('bio', {}).get('summary', u'') img = artist_dictionary.get('img', u'') event_date = r[5] # MM/DD/YYYY dt = strptime(event_date, _DATE_FORMAT) event_date = date(*dt[:3]) event_time = r[2] # HH:MM zz" if ':' in event_time: if ' ' in event_time: # convert to 24 hour time format t, z = event_time.split(' ') h, m = t.split(':') if 'p' in z.lower() and not event_time.lower() == '12:00 p.m.': h = (int(h) + 12) % 24 event_time = u"%s:%s" % (h, m) elif event_time.lower() == '12:00 a.m.': event_time = u"00:00" event_date = event_date + timedelta(days=1) else: if int(h) <= 2 or int(h) == 12: if int(h) == 12: t = u"00:%s" % m event_date = event_date + timedelta(days=1) event_time = t else: event_time = None if not event_time: event_time = None artist_location = r[3] headliner = artist_name genre = r[4] external_url = r[6].strip() event_id = external_url.split('/')[-1] if 'no hyperlink' in external_url.lower(): external_url = u'' genre_tag = genre.replace('/', ' #') title = u"%s at %s %s #%s" % (artist_name.decode('utf-8'), vn.name.decode('utf-8'), hashtag, genre_tag) Event.objects.filter(ext_event_id=event_id, ext_event_source=event_source).delete() ex = Event( ext_event_id=event_id, ext_event_source=event_source, artist=_ARTIST, creator=_ARTIST.user_profile, description=bio, is_submitted=True, is_approved=True, title=title[:120], url=(u"%s-%s" % (slugify(title)[:30], uuid4().hex[::4]))[:35], venue=vn, event_date=event_date, event_start_time=event_time, event_timezone=u'', hashtag=u'"%s"' % headliner[:200].decode('utf-8') or u'', location=location, headliner=headliner[:200] or u'', artists=u'', has_image=bool(img), ) image_content = ContentFile(get_raw_image(img)) fname, ext = os.path.splitext("default.jpg") fname = u'%s%s' % (uuid4().hex[::2], ext) ex.image.save(fname, image_content, save=False) ex._create_resized_images(raw_field=None, save=False) ex.save() print ex, ex.ext_event_id rnum += 1
def import_events(filepath, hashtag=u"#SXSWm #Showcase", location=u'austin', venue_city='Austin', venue_state='TX', venue_zip=u'', event_source='sxsw', geoloc="30.27,-97.74", **kwargs): from artist.models import ArtistProfile from event.models import Event, Venue from lastfm import get_artist from lastfm.fetch_events import get_raw_image _ARTIST = ArtistProfile.objects.get(url='riotvine-member') _DATE_FORMAT = "%m/%d/%Y" # format: 03/17/2010 f = open(filepath, 'r') lines = f.readlines() max = len(lines) rnum = 0 while True: if rnum >= max: break r = lines[rnum].strip().split('|') print rnum, r if r[1] == u'' and r[2] == u'' and r[3] == u'' and r[4] == u'': # venue row #1 if rnum + 1 >= max: break r2 = lines[rnum + 1].strip().split('|') if r2[1] == u'' and r2[2] == u'' and r2[3] == u'' and r2[4] == u'': # venue row #2 venue = r[0] venue_address = r2[0].split(')\xc2\xa0(')[0][1:].decode( 'utf-8') querystring = urlencode({ 'q': u'%s %s, %s %s' % (venue[:25], venue_address, venue_city, venue_state) }) map_url = u'http://maps.google.com/?%s' % querystring vn, created = Venue.objects.get_or_create( name=venue[:255], geo_loc=geoloc, defaults=dict( source='user-entered', address=venue_address[:255], city=venue_city[:255], state=venue_state, zip_code=venue_zip[:12], venue_url=u'', map_url=map_url, )) rnum += 1 # skip this row next time around else: # event row artist_name = r[1] artist_dictionary = get_artist(artist_name) bio = artist_dictionary.get('bio', {}).get('summary', u'') img = artist_dictionary.get('img', u'') event_date = r[5] # MM/DD/YYYY dt = strptime(event_date, _DATE_FORMAT) event_date = date(*dt[:3]) event_time = r[2] # HH:MM zz" if ':' in event_time: if ' ' in event_time: # convert to 24 hour time format t, z = event_time.split(' ') h, m = t.split(':') if 'p' in z.lower( ) and not event_time.lower() == '12:00 p.m.': h = (int(h) + 12) % 24 event_time = u"%s:%s" % (h, m) elif event_time.lower() == '12:00 a.m.': event_time = u"00:00" event_date = event_date + timedelta(days=1) else: if int(h) <= 2 or int(h) == 12: if int(h) == 12: t = u"00:%s" % m event_date = event_date + timedelta(days=1) event_time = t else: event_time = None if not event_time: event_time = None artist_location = r[3] headliner = artist_name genre = r[4] external_url = r[6].strip() event_id = external_url.split('/')[-1] if 'no hyperlink' in external_url.lower(): external_url = u'' genre_tag = genre.replace('/', ' #') title = u"%s at %s %s #%s" % (artist_name.decode('utf-8'), vn.name.decode('utf-8'), hashtag, genre_tag) Event.objects.filter(ext_event_id=event_id, ext_event_source=event_source).delete() ex = Event( ext_event_id=event_id, ext_event_source=event_source, artist=_ARTIST, creator=_ARTIST.user_profile, description=bio, is_submitted=True, is_approved=True, title=title[:120], url=(u"%s-%s" % (slugify(title)[:30], uuid4().hex[::4]))[:35], venue=vn, event_date=event_date, event_start_time=event_time, event_timezone=u'', hashtag=u'"%s"' % headliner[:200].decode('utf-8') or u'', location=location, headliner=headliner[:200] or u'', artists=u'', has_image=bool(img), ) image_content = ContentFile(get_raw_image(img)) fname, ext = os.path.splitext("default.jpg") fname = u'%s%s' % (uuid4().hex[::2], ext) ex.image.save(fname, image_content, save=False) ex._create_resized_images(raw_field=None, save=False) ex.save() print ex, ex.ext_event_id rnum += 1