def populate_db(): a1 = Artist(name="Billy Joel", hometown="Long Island, NY") a2 = Artist(name="Tash Sultana", hometown="Melbourne, Australia") a3 = Artist(name="Mac Miller", hometown="Pittsburgh, PA") a4 = Artist(name="Red Hot Chili Peppers", hometown="Los Angeles, CA") db.session.add_all([a1, a2, a3, a4]) db.session.commit() s1 = Song(name="Zanzibar", artist=a1) s2 = Song(name="Mystik", artist=a2) s3 = Song(name="Woods", artist=a3) s4 = Song(name="The Longest Wave", artist=a4) db.session.add_all([s1, s2, s3, s4]) db.session.commit() print(s1) p1 = Playlist(name="Rock") p2 = Playlist(name="Slow Jams") stp1 = SongToPlaylist(song=s1, playlist=p1) stp2 = SongToPlaylist(song=s2, playlist=p1) stp3 = SongToPlaylist(song=s3, playlist=p2) stp4 = SongToPlaylist(song=s4, playlist=p2) db.session.add_all([p1, p2, stp1, stp2, stp3, stp4]) db.session.commit() print("Artist - Woods", s3.artist.name) return "Database has been populated."
def test_artist_track_relationship(self, memory_db): artist_1 = Artist(spotify_id='artist_spotify_id_1', artist_name='artist_name_1', followers=11) artist_2 = Artist(spotify_id='artist_spotify_id_2', artist_name='artist_name_2', followers=22) memory_db.session.add_all([artist_1, artist_2]) memory_db.session.commit() track_1 = Track(track_id='spotify_id_1', track_name='track_1', artist_id=1) track_2 = Track(track_id='spotify_id_2', track_name='track_2', artist_id=1) track_3 = Track(track_id='spotify_id_3', track_name='track_3', artist_id=2) memory_db.session.add_all([track_1, track_2, track_3]) memory_db.session.commit() assert track_1.artist == artist_1 assert track_2.artist == artist_1 assert track_3.artist == artist_2
def reset_db(): flash("Resetting database: deleting old data and repopulating with dummy data") # clear all data from all tables meta = db.metadata for table in reversed(meta.sorted_tables): print('Clear table {}'.format(table)) db.session.execute(table.delete()) db.session.commit() artist1 = Artist(name='Shane Fox', hometown='Delmar', description='He rocks') artist2 = Artist(name='Doug Turnbull', hometown='Ithaca', description='He always rocks') artist3 = Artist(name='John Doe', hometown='Cortland', description='He never rocks') db.session.add_all([artist1, artist2, artist3]) db.session.commit() d1 = datetime(2019, 10, 19, 20, 0) event1 = Event(title='Jam Fest', date=d1, venueID=1) d2 = datetime(2019, 11, 15, 21, 0) event2 = Event(title='Turn up', date=d2, venueID=1) d3 = datetime(2019, 12, 5, 19, 0) event3 = Event(title='Fun Time', date=d3, venueID=3) db.session.add_all([event1, event2, event3]) db.session.commit() venue1 = Venue(title='The Haunt', city='Ithaca', state='New York', capacity=100) venue2 = Venue(title='Moonies', city='Ithaca', state= 'New York', capacity=200) venue3 = Venue(title='Silky Jones', city='Ithaca', state='New York', capacity=300) db.session.add_all([venue1, venue2, venue3]) db.session.commit() a2e1 = ArtistToEvent(artist=artist1, event=event1) a2e2 = ArtistToEvent(artist=artist2, event=event1) a2e3 = ArtistToEvent(artist=artist3, event=event3) a2e4 = ArtistToEvent(artist=artist1, event=event3) db.session.add_all([a2e1, a2e2, a2e3, a2e4]) db.session.commit() return render_template('index.html', title='Home')
def seed_artists(): jao = Artist( name='Jao', imageUrl= 'https://images.genius.com/d0af812a25991286af3e1d3f2cf27def.1000x1000x1.png' ) stayc = Artist( name='STAYC', imageUrl= 'https://images.genius.com/f20b57fc8e0eec49da30d22acf7b5b46.766x766x1.png' ) ozuna = Artist( name='Ozuna', imageUrl= 'https://images.genius.com/80bdeecd185f21dcc0eed81d8bac27ee.918x918x1.png' ) anuel = Artist( name='Anuel AA', imageUrl= 'https://images.genius.com/dda934aaa976e32ef040db739b64ed68.1000x1000x1.png' ) rauw = Artist( name='Rauw Alejandro', imageUrl= 'https://images.genius.com/f553b78a0795edb547d2cef8b5be8b79.483x483x1.jpg' ) db.session.add(jao) db.session.add(stayc) db.session.add(ozuna) db.session.add(anuel) db.session.add(rauw) db.session.commit()
def reset_db(): flash( "Resetting database: deleting old data and repopulating with dummy data" ) # clear all data from all tables meta = db.metadata for table in reversed(meta.sorted_tables): print('Clear table {}'.format(table)) db.session.execute(table.delete()) db.session.commit() default_venues = [ Venue(name='Stewart Park', address='1 James L Gibbs Dr, Ithaca, NY 14850'), Venue(name='The Haunt', address='702 Willow Ave, Ithaca, NY 14850'), Venue(name='Ithaca College', address='953 Danby Rd, Ithaca, NY 14850') ] dates = [ datetime(2018, 9, 21, 20, 0, 0), datetime(2018, 3, 7, 20, 0, 0), datetime(2034, 5, 18, 21, 0, 0) ] default_events = [ Event(name='Cayuga Sound Festival', time=dates[0], venue_id=1), Event(name='Matt and Kim Concert', time=dates[1], venue_id=2), Event(name='Young The Giant Concert', time=dates[2], venue_id=2), Event(name='Jon Bellion Concert', time=dates[1], venue_id=3) ] default_artists = [ Artist(name='X Ambassadors', hometown='Ithaca, NY', description='The X Ambassadors description'), Artist(name='Young The Giant', hometown='Irvine, CA', description='Young The Giant description'), Artist(name='Matt and Kim', hometown='Boston, MA', description='Matt and Kim description'), Artist(name='Roots', hometown='Philadelphia, PA', description='Roots description'), Artist(name='Jon Bellion', hometown='Smithtown, NY', description='Jon Bellion description') ] default_a_to_e = [ ArtistToEvent(artist_id=1, event_id=1), ArtistToEvent(artist_id=2, event_id=1), ArtistToEvent(artist_id=3, event_id=1), ArtistToEvent(artist_id=3, event_id=2), ArtistToEvent(artist_id=2, event_id=3), ArtistToEvent(artist_id=4, event_id=1), ArtistToEvent(artist_id=5, event_id=4) ] db.session.add_all(default_artists) db.session.add_all(default_venues) db.session.add_all(default_events) db.session.add_all(default_a_to_e) db.session.commit() return redirect(url_for('index'))
def populate_db(): c1 = City(name='Ithaca, NY') c2 = City(name='Binghamton, NY') c3 = City(name='Syracuse, NY') c4 = City(name='Rochester, NY') db.session.add_all([c1, c2, c3, c4]) db.session.commit() a1 = Artist(name="Driftwood", description="Folk Rock", cityID=c2.id) a2 = Artist(name="Quail", description="Funk and Brass", cityID=c1.id) a3 = Artist(name="VeeDaBee", description="Rock Band", cityID=c1.id) a4 = Artist(name="Danielle Ponder", description="Soul", cityID=c4.id) db.session.add_all([a1, a2, a3, a4]) db.session.commit() v1 = Venue(name='The Haunt', cityID=c2.id) v2 = Venue(name='State Theater', cityID=c1.id) v3 = Venue(name='Stewart Park', cityID=c1.id) v4 = Venue(name='University', cityID=c2.id) v5 = Venue(name='Oncenter', cityID=c3.id) db.session.add_all([v1, v2, v3, v4, v5]) db.session.commit() e1 = Event(name='Ithaca Porchfest', time=datetime(2020, 11, 5, 20, 00), venueID=v3.id) e2 = Event(name='2020 Tour', time=datetime(2020, 10, 20, 18, 00), venueID=v5.id) e3 = Event(name='Anniversary Concert', time=datetime(2020, 10, 20, 19, 00), venueID=v1.id) e4 = Event(name='2020 Tour', time=datetime(2020, 10, 29, 18, 00), venueID=v2.id) e5 = Event(name='2020 Tour', time=datetime(2020, 10, 20, 12, 00), venueID=v4.id) db.session.add_all([e1, e2, e3, e4, e5]) db.session.commit() x1 = ArtistToEvent(artistID=a1.id, eventID=e3.id) x2 = ArtistToEvent(artistID=a2.id, eventID=e3.id) x3 = ArtistToEvent(artistID=a1.id, eventID=e1.id) x4 = ArtistToEvent(artistID=a3.id, eventID=e4.id) x5 = ArtistToEvent(artistID=a4.id, eventID=e5.id) x6 = ArtistToEvent(artistID=a3.id, eventID=e2.id) db.session.add_all([x1, x2, x3, x4, x5, x6]) db.session.commit() u1 = User(username='******', email=('*****@*****.**'), password_hash='Password') db.session.add(u1) db.session.commit() return render_template('base.html', title='Populate DB')
def test_put_errors(server): with server.app_context(): artist = Artist("a") db.session.add(artist) artist2 = Artist("b") db.session.add(artist2) db.session.commit() assert Artist.query.count() == 2 r = requests.put(server.url + "/artist/{}".format(artist.id), data={ "name": "b" }) assert r.status_code == 422
def setAlbumArtist(album, artist_name): app.logger.info('setAlbumArtist') if not artist_name: raise Exception('Album has no artist name given') # update model artist = Artist.query.filter_by(name=artist_name).first() if not artist: artist = Artist(artist_name) db.session.add(artist) db.session.commit() app.logger.info('{} <= {}'.format(artist, artist_name)) album.artist_id = artist.id # update tag app.logger.info('Updating artist {} for album {}'.format( artist_name, album)) for song in album.songs: if song.path_name.lower().endswith('mp3'): tags = ID3(song.abs_path) tags["TPE1"] = TPE1(encoding=3, text=u'{}'.format(artist_name)) tags.save(song.abs_path) elif song.path_name.lower().endswith('m4a'): tags = MP4(song.abs_path) raise Exception('Do song info for mp4') db.session.commit() app.logger.info('Update album with artist in db')
def create_artist(): '''create new artist''' form = ArtistForm() if request.method == "POST": # import ipdb # ipdb.set_trace() if form.validate_on_submit(): artist = Artist( name=form.name.data, genres=",".join(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, seeking_description=form.seeking_description.data, image_link=form.image_link.data ) db.session.add(artist) db.session.commit() flash('Artist ' + artist.name + ' was successfully listed!') return redirect(url_for('artists')) else: flash("Found errors: {}".format(form.errors)) return render_template('forms/new_artist.html', form=form)
def manageArtistAdd(): """ 新增歌手 """ if request.method == "POST": artistName = request.form.get("artistName") style = request.form.get("style") imgURL = request.form.get("imgURL") isHot = request.form.get("isHot") # 判断歌手是否存在 artist = Artist.query.filter_by(artistName=artistName).first() res = {} if artist: res["status"] = -2 res["message"] = "歌手已经存在" return jsonify(res) # 写入到Artist表 try: artist = Artist( artistName = artistName, style = int(style), imgURL = imgURL, isHot = int(isHot) ) db.session.add(artist) db.session.commit() res["status"] = 1 res["message"] = "新增成功" except Exception as e: res["status"] = -1 res["message"] = "新增失败" return jsonify(res) return render_template("home/manageArtistAdd.html")
def json(): """"Method for inital importation of data.""" data = request.data.decode("utf-8") data = loads(data) if data['key'] == app.config['SECRET_KEY']: data = data['data'] for i in data: u = Artist(name=i['name'], life=i['life'], school=i['school'], timeframe=i['timeframe']) db.session.add(u) u = Artist.query.filter_by(name=i['name']).first_or_404() for j in i['art']: a = Art(title=j['title'], date=j['date'], technique=j['technique'], location=j['location'], url=j['url'], form=j['form'], type=j['painting_type'], img_url=j['img'], artist_id=u.id) db.session.add(a) db.session.commit() return "Thanks for the data" else: return "Please provide Auth"
def add_update_db(url): track_id = url[-22:] track_uri = str("spotify:track:") + track_id search = sp.track(track_uri) track_name = search['name'] track_popularity = search['popularity'] duration = search['duration_ms'] explicit = search['explicit'] release_date = search['album']['release_date'] year = release_date[:3] artist_idx = search['artists'][0]['id'] search = sp.artist(artist_idx) genres = json.dumps(search['genres']) artist_name = search['name'] artist_uri = search['uri'] artist_popularity = search['popularity'] search = sp.audio_features(track_id) danceability = search[0]['danceability'] energy = search[0]['energy'] key = search[0]['key'] loudness = search[0]['loudness'] mode = search[0]['mode'] speechiness = search[0]['speechiness'] acousticness = search[0]['acousticness'] instrumentalness = search[0]['instrumentalness'] liveness = search[0]['liveness'] valence = search[0]['valence'] tempo = search[0]['tempo'] x = Artist(id=artist_idx, name=artist_name, uri=artist_uri, genres=genres, popularity=artist_popularity) y = Track(id=track_id, name=track_name, uri=track_uri, popularity=track_popularity, duration=duration, explicit=explicit, release_date=release_date, year=year, artist_id=artist_idx, danceability=danceability, energy=energy, key=key, loudness=loudness, mode=mode, speechiness=speechiness, acousticness=acousticness, instrumentalness=instrumentalness, liveness=liveness, valence=valence, tempo=tempo) sess.merge(x) sess.merge(y) sess.commit()
def create_artist_submission(): error = False data = request.form try: artist = Artist() artist.name = data['name'] artist.city = data['city'] artist.state = data['state'] artist.phone = data.get('phone', '') artist.facebook_link = data.get('facebook_link', '') artist.genres = [ ArtistGenres(genre=GenreEnum[genre]) for genre in data.getlist('genres') ] db.session.add(artist) db.session.commit() except: error = True db.session.rollback() finally: data = artist.to_dict() db.session.close() if not error: flash(f'Artist {data["name"]} was successfully listed!', 'alert-success') else: flash( f'An error occurred. Artist {data["name"]} could not be listed. \ Does the artist exist already?', 'alert-danger') return render_template('pages/home.html')
def manageArtistAdd(): ''' 新增歌手 ''' if request.method == "POST": # 提交注册表单 artistName = request.form.get("artistName") style = request.form.get("style") imgURL = request.form.get("imgURL") isHot = request.form.get("isHot") # 判断歌手是否存在 artist = Artist.query.filter_by( artistName=artistName).first() # 获取用户信息 if artist: res = {} res['status'] = -2 res['message'] = '该歌手已存在' return jsonify(res) # 写入到Artist表 try: # 为Artist类属性赋值 artist = Artist(artistName=artistName, style=int(style), imgURL=imgURL, isHot=int(isHot)) db.session.add(artist) # 添加数据 db.session.commit() # 提交数据 res = {} res['status'] = 1 res['message'] = '添加成功' except: res = {} res['status'] = -1 res['message'] = '添加失败' return jsonify(res) return render_template('home/manageArtistAdd.html')
def _make_db_artist(artist): db_artist = Artist( id=artist['id'], name=artist['name'], ) db.session.add(db_artist) return db_artist
def create_data(): for i in range(100): db.session.add(Artist()) for j in range(1000): date = datetime.date.today() - datetime.timedelta(j) value = (1000 - j) / (i + 1) db.session.add( Metric(artist_id=i + 1, date=date, value=value)) db.session.commit()
def create_artist(name): artist = Artist.query.filter_by(name=name).first() if artist is None: artist = Artist(name=name) db.session.add(artist) db.session.commit() click.echo("The artist {} has been created!".format(name)) else: click.echo("The artist {} was used!".format(name))
def reset_db(): flash( "Resetting database: deleting old data and repopulating with dummy data" ) meta = db.metadata for table in reversed(meta.sorted_tables): print('Clear table {}'.format(table)) db.session.execute(table.delete()) db.session.commit() artist1 = Artist(name="Drake", description="Soon to be added") artist2 = Artist(name='Kendrick Lamar', description="Added after Drake") venue1 = Venues(location='Baltimore Soundstage, Maryland', date='01/24/2018') venue2 = Venues(location='The 20th Century Theater, Ohio', date='04/28/2018') venue3 = Venues(location='The New Parish, California', date='04/29/2018') event1 = Events(name='Aubrey & The Three Migos ', price='$350', venue_id=1, event_date=datetime.utcnow()) event2 = Events(name='Leeds Festival 2018', price='$170', venue_id=2, event_date=datetime.utcnow()) a2e = ArtistToEvent(Artist_id=1, Event_id=1) a2e1 = ArtistToEvent(Artist_id=2, Event_id=2) db.session.add(artist1) db.session.add(artist2) db.session.add(venue1) db.session.add(venue2) db.session.add(venue3) db.session.add(event1) db.session.add(event2) db.session.add(a2e) db.session.add(a2e1) db.session.commit() return redirect(url_for('index'))
def newArtists(): form = NewArtistForm() if form.validate_on_submit(): flash('Artist info entered for name {}'.format( form.name.data, form.hometown.data, form.description.data)) a = Artist(name=form.name.data, hometown=form.hometown.data) db.session.add(a) db.session.commit() return redirect(url_for("artists")) return render_template('newArtists.html', title='New Artists', form=form)
def new_artist(): form = NewArtistForm() if form.validate_on_submit(): flash_message = 'New Artist Created: {}'\ .format(form.name.data) flash(flash_message) a = Artist(name=form.name.data, hometown=form.hometown.data, description=form.description.data) db.session.add(a) db.session.commit() return redirect(url_for('artists')) return render_template('new_artist.html', title="New Artist", form=form)
def enterartist(): form = ArtistForm() if form.validate_on_submit(): artist = Artist(artistname=form.artistname.data, artistlogo=form.artistlogo.data) db.session.add(artist) db.session.commit() flash('You Submitted {}'.format(form.artistname.data)) return redirect('/music') return render_template('enter_artist.html', title='Music', form=form)
def test_get_one(server): with server.app_context(): artist = Artist("a") db.session.add(artist) db.session.commit() assert Artist.query.count() == 1 r = requests.get(server.url + "/artist/{}".format(artist.id)) assert r.status_code == 200 assert r.json()['name'] == artist.name
def test_get_many(server, arguments, names): with server.app_context(): for name in ("a", "b", "c"): db.session.add(Artist(name)) db.session.commit() r = requests.get(server.url + "/artists?{}".format(urlencode(arguments))) assert r.status_code == 200 items = r.json() assert len(items) == len(names) assert list(map(lambda x: x["name"], items)) == names
def create_artist(): form = ArtistForm() if form.validate_on_submit(): artist1 = Artist(name=form.artist.data, description=form.bio.data) db.session.add(artist1) db.session.commit() flash('Artist {} has been created'.format(artist1)) return render_template('create_artist.html', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('index')) form = RegistrationForm() if form.validate_on_submit(): user = Artist(username=form.username.data, email=form.email.data) user.set_password(form.password.data) db.session.add(user) db.session.commit() flash('Congratulations, you are now a registered user!') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def addArtist(): form = newArtistForm() if form.validate_on_submit(): flash('Artist submitted with name="{}", hometown="{}", and bio="{}"'. format(form.artistName.data, form.hometown.data, form.bio.data)) artist = Artist(name=form.artistName.data, hometown=form.hometown.data, bio=form.bio.data) db.session.add(artist) db.session.commit() return redirect(url_for('artists')) return render_template('addArtist.html', title='Add Artist', form=form)
def test_post_errors_on_unique(server): with server.app_context(): artist = Artist("a") db.session.add(artist) db.session.commit() assert Artist.query.count() == 1 r = requests.post(server.url + "/artists", data={"name": "a"}) assert r.status_code == 422 assert Artist.query.count() == 1
def createNewArtist(): form = ArtistForm() if form.validate_on_submit(): flash('New artist request {}'.format(form.name.data)) my_artist = Artist(name=form.name.data, hometown=form.hometown.data, description=form.description.data) db.session.add(my_artist) db.session.commit() flash('New artist created.') return redirect(url_for('listOfArtists')) return render_template('newArtist.html', title="newArtist", form=form)
def create_artist(): form = ArtistForm() # if form was submitted and contained no errors if form.validate_on_submit(): new_artist = Artist(name=form.name.data) db.session.add(new_artist) db.session.commit() flash('New artist was created successfully.') return redirect(url_for('main.homepage')) return render_template('create_artist.html', form=form)
def test_delete(server): with server.app_context(): artist = Artist("a") db.session.add(artist) db.session.commit() assert Artist.query.count() == 1 r = requests.delete(server.url + "/artist/{}".format(artist.id)) assert r.status_code == 204 with server.app_context(): assert Artist.query.count() == 0