def upload(request): context = {"status": "norm"} if request.method == "POST": rb = xlrd.open_workbook(settings.BASE_DIR + '/Orders/cat.xls', formatting_info=True) sheet = rb.sheet_by_index(0) base = {} for rownum in range(sheet.nrows): row = sheet.row_values(rownum) row[0] = int(row[0]) if sheet.cell(rownum, 1).ctype == 3: row[1] = xlrd.xldate_as_tuple(row[1], 0) tmp = str(row[1][4]) if tmp == "0": tmp = "00" row[1] = str(row[1][3]) + ":" + tmp if sheet.cell(rownum, 1).ctype == 2: row[1] = int(row[1]) b1 = Artist(name=row[2]) try: b1.save() except: b1 = Artist.objects.filter(name=row[2])[0] s = Song(number=row[0], tittle=row[1], minus_quality=row[4], back_vocal=row[3], karaoke_system="test", artist=b1) s.save() return render(request, 'Orders/upload.html', context) return render(request, 'Orders/upload.html', context)
def parser_artist(artist_id): create_app() process = Process.get_or_create(id=artist_id) # Process以歌手为单位 if process.is_success: return print('Starting fetch artist: {}'.format(artist_id)) start = time.time() process = Process.get_or_create(id=artist_id) tree = get_tree(ARTIST_URL.format(artist_id)) # 使用requests获取页面文本,转化为lxml对象 artist = Artist.objects.filter(id=artist_id) if not artist: # 如果之前没抓过 artist_name = tree.xpath('//h2[@id="artist-name"]/text()')[0] picture = tree.xpath( '//div[contains(@class, "n-artist")]//img/@src')[0] artist = Artist(id=artist_id, name=artist_name, picture=picture) artist.save() else: # 如果之前抓过,但是该歌手的歌曲没抓完 artist = artist[0] song_items = tree.xpath('//div[@id="artist-top50"]//ul/li/a/@href') songs = [] for item in song_items: song_id = item.split('=')[1] song = parser_song(song_id, artist) # 进入抓取和解析歌手模式 if song is not None: songs.append(song) artist.songs = songs artist.save() process.make_succeed() # 标记歌手下的热门歌曲的热门评论抓完 print('Finished fetch artist: {} Cost: {}'.format(artist_id, time.time() - start))
def create_artist_submission(): form = ArtistForm(csrf_enabled=True) if form.validate_on_submit(): artist_data = dict(name=form.name.data, genres=list(form.genres.data), city=form.city.data, state=form.state.data, phone=form.phone.data, website=form.website.data, facebook_link=form.facebook_link.data, seeking_venue=form.seeking_venue.data, seek_description=form.seek_description.data, image_link=form.image_link.data) check_artist_exists = Artist.query.filter_by( name=form.name.data).first() if check_artist_exists: flash('Artist with that name already exists') return render_template('pages/home.html') new_artist = Artist(**artist_data) new_artist.save() flash('Artist ' + request.form['name'] + ' was successfully added!') else: errors = form.errors for key, error in errors.items(): flash(f'{key} Error ' + " => " + f"{error[0]} :(") return render_template('pages/home.html')
def parser_artist(artist_id): create_app() process = Process.get_or_create(id=artist_id) if process.is_success: return print 'Starting fetch artist: {}'.format(artist_id) start = time.time() process = Process.get_or_create(id=artist_id) tree = get_tree(ARTIST_URL.format(artist_id)) artist = Artist.objects.filter(id=artist_id) if not artist: artist_name = tree.xpath('//h2[@id="artist-name"]/text()')[0] picture = tree.xpath( '//div[contains(@class, "n-artist")]//img/@src')[0] artist = Artist(id=artist_id, name=artist_name, picture=picture) artist.save() else: artist = artist[0] song_items = tree.xpath('//div[@id="artist-top50"]//ul/li/a/@href') songs = [] for item in song_items: song_id = item.split('=')[1] song = parser_song(song_id, artist) if song is not None: songs.append(song) artist.songs = songs artist.save() process.make_succeed() print 'Finished fetch artist: {} Cost: {}'.format( artist_id, time.time() - start)
def add_to_db(audio_files): for audio_file in audio_files: audio_file_id3 = eyed3.load(audio_file) # If the artist, album or track doesn't exist in the database, create # table(s) for them. try: if not Artist.objects.filter(name=audio_file_id3.tag.artist).exists(): artist = Artist(name=audio_file_id3.tag.artist) artist.save() if not Album.objects.filter(title=audio_file_id3.tag.album).exists(): album = Album(title=audio_file_id3.tag.album, \ artist=artist) album.save() if not Track.objects.filter(title=audio_file_id3.tag.title).exists(): track = Track(title=audio_file_id3.tag.title, \ album=album, \ artist=artist, \ fspath=audio_file, \ media_url=MEDIA_URL + audio_file.split(MEDIA_ROOT)[1]) track.save() print 'Added to DB: ' + audio_file_id3.tag.title except Exception as e: print 'Error: ' + e
def add_record(release): from models import Record, Artist, Track release_discogs_id = release.id try: # Check if we already have this album existing = Record.objects.get(discogs_id=release_discogs_id) return existing except Record.DoesNotExist: # Process record record_title = release.title if (len(record_title.split('- '))>1): record_title = record_title.split('- ')[1] record = Record(discogs_id = release_discogs_id, title = record_title, year = release.year, thumb = release.thumb, notes = release.notes) record.save() # Process artists for release_artist in release.artists: artist = Artist(discogs_id=release_artist.id, name=release_artist.name) artist.save() record.artists.add(artist) # Process tracklist for release_track in release.tracklist: track = Track() track.position = release_track.position track.title = release_track.title track.duration = release_track.duration track.save() record.tracklist.add(track) record.save() return record
def artist_application(request): latest_news = NewsItem.objects.all()[0] if request.method == 'POST': form = ArtistApplication(request.POST) if form.is_valid(): artist = Artist( name=form.cleaned_data['name'], description=form.cleaned_data['description'], phone=form.cleaned_data['phone'], website=form.cleaned_data['website'], soundcloud=form.cleaned_data['soundcloud'], facebook=form.cleaned_data['facebook'], myspace=form.cleaned_data['myspace'], lastfm=form.cleaned_data['lastfm'], twitter=form.cleaned_data['twitter'], youtube=form.cleaned_data['youtube'], resident_advisor=form.cleaned_data['resident_advisor']) artist.save() return redirect('/artists/application-successful/') else: form = ArtistApplication() return render_to_response('artist_application.html', { 'form': form, 'latest_news': latest_news }, context_instance=RequestContext(request))
def parser_artist(artist_id): create_app() process = Process.get_or_create(id=artist_id) if process.is_success: return print 'Starting fetch artist: {}'.format(artist_id) start = time.time() process = Process.get_or_create(id=artist_id) tree = get_tree(ARTIST_URL.format(artist_id)) artist = Artist.objects.filter(id=artist_id) if not artist: artist_name = tree.xpath('//h2[@id="artist-name"]/text()')[0] picture = tree.xpath( '//div[contains(@class, "n-artist")]//img/@src')[0] artist = Artist(id=artist_id, name=artist_name, picture=picture) artist.save() else: artist = artist[0] song_items = tree.xpath('//div[@id="artist-top50"]//ul/li/a/@href') songs = [] for item in song_items: song_id = item.split('=')[1] song = parser_song(song_id, artist) if song is not None: songs.append(song) artist.songs = songs artist.save() process.make_succeed() print 'Finished fetch artist: {} Cost: {}'.format(artist_id, time.time() - start)
def parser_artist(artist_id): create_app() process = Process.get_or_create(id=artist_id) if process.is_success: print "find process artist finished ,return" return print 'Starting fetch artist: {}'.format(artist_id) start = time.time() process = Process.get_or_create(id=artist_id) tree = get_tree(ARTIST_URL.format(artist_id)) #get artist url if tree==None: print "fetch artist url get none,return !" return artist = Artist.objects.filter(id=artist_id) if not artist: print "create artist "+str(artist_id) artist_name = tree.xpath('//h2[@id="artist-name"]/text()')[0] picture = tree.xpath( '//div[contains(@class, "n-artist")]//img/@src')[0] artist = Artist(id=artist_id, name=artist_name, picture=picture) artist.save() else: artist = artist[0] print "artist exist " + str(artist_id) print "fetching all song comments" song_items = tree.xpath('//div[@id="artist-top50"]//ul/li/a/@href') #song_items2=tree.xpath('//ul[@class="f-hide"]/li/a/@href') the same songs = [] print song_items if song_items==[]: print "Artist get no songs ,return fetch artist {}".format(artist_id) return for item in song_items: song_id = item.split('=')[1] song = parser_song(song_id, artist) if song is None: print "parse song failed,return " return else: songs.append(song) artist.songs = songs artist.save() process.make_succeed() print 'Finished fetch artist: {} Cost: {}'.format( artist_id, time.time() - start)
def add_artists(request, data): dajax = Dajax() data = simplejson.loads(data) count = int(data['count']) for i in range(count): artistName = ("test_artist_%d") % (uuid.uuid4()) artist = Artist(name=artistName) artist.save() successMessage = "Successfully added [%d] artists!" % count dajax.assign('#message', 'innerHTML', successMessage) return dajax.json()
def test(request): access_token = "" # token_info = sp_oauth.get_cached_token() # if token_info: # print "Found cached token!" # access_token = token_info['access_token'] # else: code = request.GET.get('code') if code: print "Found Spotify auth code in Request URL! Trying to get valid access token..." token_info = sp_oauth.get_access_token(code) access_token = token_info['access_token'] if access_token: print "Access token available! Trying to get user information..." sp = spotipy.Spotify(access_token) current_user = sp.current_user() artists = sp.current_user_top_artists(limit=50) username = current_user['id'] current_users = SpotifyUser.objects.filter(username=username) if current_users: print current_users else: new_user = SpotifyUser(username=username) new_user.save() i = 1 for item in artists['items']: artist_id = item['id'] print item['name'] + ": " + artist_id matching_artists = Artist.objects.filter(spotify_id=artist_id) if matching_artists: the_artist = matching_artists[0] else: the_artist = Artist(spotify_id=artist_id, name=item['name']) the_artist.save() user_artist = UserArtist(artist=the_artist, user=new_user, rank=i) user_artist.save() i = i + 1 results_string = "<ol>" for item in artists['items']: results_string += "<li><img src='" + item['images'][1]['url'] + "'/>" + item['name'] + "</li>" results_string += "</ol>" return HttpResponse(results_string) else: return HttpResponse(htmlForLoginButton())
def new_song(request): if request.method == "POST": form = SongForm(request.POST) if form.is_valid(): data = analyze(form.cleaned_data['lyrics']) try : artist = Artist.objects.all().filter(name=form.cleaned_data['artist-name']) except: artist = Artist(name=form.cleaned_data['artist_name']) artist.save() song = Song(name=form.cleaned_data['song_name'], lyrics = form.cleaned_data['lyrics'], artist=artist, number_of_words= data['total_words'], number_unique_words=data['unique_words'], unique_word_percent=data['percentage'], repeated_rhymes=data['repeated_rhymes'], bad_words=data['bad_words'], thug_rating=data['thug_rating'], avg_syllables=data['thug_rating']) song.save() return redirect("/") form = SongForm() return render(request, 'lyrics/new_song.html', { 'form': form })
def main(): new_artist = Artist.create(name="Newsboys") new_album = Album( artist=new_artist, title="Album title", publisher="Sparrow", release_date=datetime.date(1988, 12, 1), media_type="CD", ) new_album.save() # batch save albums = [{ "artist": new_artist, "title": "Hell is for Wimps", "release_date": datetime.date(1990, 7, 31), "publisher": "Sparrow", "media_type": "CD" }, { "artist": new_artist, "title": "Love Liberty Disco", "release_date": datetime.date(1999, 11, 16), "publisher": "Sparrow", "media_type": "CD" }, { "artist": new_artist, "title": "Thrive", "release_date": datetime.date(2002, 3, 26), "publisher": "Sparrow", "media_type": "CD" }] for album in albums: a = Album(**album) a.save() bands = ["MXPX", "Kutless", "Thousand Foot Krutch"] for band in bands: artist = Artist(name=band) artist.save() print("[+] done")
def artist_application(request): latest_news = NewsItem.objects.all()[0] if request.method == 'POST': form = ArtistApplication(request.POST) if form.is_valid(): artist = Artist(name = form.cleaned_data['name'], description = form.cleaned_data['description'], phone = form.cleaned_data['phone'], website = form.cleaned_data['website'], soundcloud = form.cleaned_data['soundcloud'], facebook = form.cleaned_data['facebook'], myspace = form.cleaned_data['myspace'], lastfm = form.cleaned_data['lastfm'], twitter = form.cleaned_data['twitter'], youtube = form.cleaned_data['youtube'], resident_advisor = form.cleaned_data['resident_advisor']) artist.save() return redirect('/artists/application-successful/') else: form = ArtistApplication() return render_to_response('artist_application.html', {'form': form, 'latest_news': latest_news}, context_instance=RequestContext(request))
def create_artist(): form = ArtistForm() if request.method == 'POST': if form.validate_on_submit(): print(request.form) artist = Artist(request.form) result = artist.save(new=True) print(result) if not result['success']: flash('error saving artist {}'.format(request.form['name'])) return render_template('forms/new_artist.html', form=form) else: flash('Artist ' + request.form['name'] + ' was successfully listed!') return render_template('pages/home.html') flash('some values submitted were incorrect') return render_template('forms/new_artist.html', form=form) return render_template('forms/new_artist.html', form=form)
def add_artist(name, email): new_artist = Artist(name=name, email=email) new_artist.save()
import random from models import Artist, Album, Song, Tag, Comment, Playlist import lorem from faker import Faker fake = Faker() # Artists peep = Artist(name='We Are All Astronauts', artistDescription="Ether is an American producer from Nashville. Ether also produces and posts his songs to his Soundcloud.", artistImageUrl="https://instagram.fktw1-1.fna.fbcdn.net/vp/df0702bb3af8c1581864b98427644d8c/5C8E65A0/t51.2885-15/e35/s320x320/26186297_1144045615726747_3534440781014106112_n.jpg") peep.save() # Albums crybaby = Album(artistId=peep, albumName='Purity', albumDescription='Purity is an album by Ether, released at the 10th of June, 2016. It features Jazpe members Lapse and Kaleido.') crybaby.save() # Songs songs = [] helpless = Song(artistId=peep, albumId=crybaby, name='Helpless', musicSrc='https://s3-eu-west-1.amazonaws.com/melody-cloud-songs/Crybaby.mp3', waveformImgUrl='https://s3-eu-west-1.amazonaws.com/melody-cloud-waveforms/Crybaby.mp3.png', amountOfPlays=random.randint(10000, 100000), amountOfLikes=random.randint(1000, 10000), description='First song in the album', lyrics=lorem.text()) songs.append(helpless) needaname_song = Song(artistId=peep, albumId=crybaby, name='Need a Name', musicSrc='https://s3-eu-west-1.amazonaws.com/melody-cloud-songs/LilJeep.mp3', waveformImgUrl='https://s3-eu-west-1.amazonaws.com/melody-cloud-waveforms/LilJeep.mp3.png', amountOfPlays=random.randint(10000, 100000), amountOfLikes=random.randint(1000, 10000), description='Second song in the album', lyrics=lorem.text()) songs.append(needaname_song) awakening_song = Song(artistId=peep, albumId=crybaby, name='Awakening', musicSrc='https://s3-eu-west-1.amazonaws.com/melody-cloud-songs/Yesterday.mp3', waveformImgUrl='https://s3-eu-west-1.amazonaws.com/melody-cloud-waveforms/Yesterday.mp3.png', amountOfPlays=random.randint(10000, 100000), amountOfLikes=random.randint(1000, 10000), description='Third song in the album', lyrics=lorem.text()) songs.append(awakening_song) waves = Song(artistId=peep, albumId=crybaby, name='Waves', musicSrc='https://s3-eu-west-1.amazonaws.com/melody-cloud-songs/AbsoluteInDoubt.mp3', waveformImgUrl='https://s3-eu-west-1.amazonaws.com/melody-cloud-waveforms/AbsoluteInDoubt.mp3.png', amountOfPlays=random.randint(10000, 100000), amountOfLikes=random.randint(1000, 10000), description='Fourth song in the album', lyrics=lorem.text()) songs.append(waves) for song in songs: song.save()