def populate_shows(): for show in shows_data: data = Show( venue_id=show["venue_id"], artist_id=show["artist_id"], start_time=show["start_time"], # address = show["address"], # city = show["city"], # state = show["state"], # phone = show["phone"], # website = show["website"], # facebook_link = show["facebook_link"], # seeking_talent = show["seeking_talent"], # # seeking_description = show["seeking_description"], # image_link = show["image_link"], # past_shows = show["past_shows"], # upcoming_shows = show["upcoming_shows"], # past_shows_count = show["past_shows_count"], # upcoming_shows_count = show["upcoming_shows_count"] ) db.session.add(data) db.session.commit() # function execution # ---------------------------------------------------------------------------- # populate_artists() # uncheck to populate # populate_venues() # uncheck to populate # populate_shows() # uncheck to populate
def dummy_show_data(): error = False try: for data in show_data: sh = Show(**data) db.session.add(sh) db.session.commit() print("data successfully created") except: error = True db.session.rollback() print(f'Show: {sys.exc_info()}') finally: db.session.close()
def create_shows(): data = [{ "venue_id": 1, "venue_name": "The Musical Hop", "artist_id": 1, "artist_name": "Guns N Petals", "artist_image_link": "https://images.unsplash.com/photo-1549213783-8284d0336c4f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=300&q=80", "start_time": "2019-05-21T21:30:00.000Z" }, { "venue_id": 3, "venue_name": "Park Square Live Music & Coffee", "artist_id": 2, "artist_name": "Matt Quevedo", "artist_image_link": "https://images.unsplash.com/photo-1495223153807-b916f75de8c5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80", "start_time": "2019-06-15T23:00:00.000Z" }, { "venue_id": 3, "venue_name": "Park Square Live Music & Coffee", "artist_id": 3, "artist_name": "The Wild Sax Band", "artist_image_link": "https://images.unsplash.com/photo-1558369981-f9ca78462e61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=794&q=80", "start_time": "2035-04-01T20:00:00.000Z" }, { "venue_id": 3, "venue_name": "Park Square Live Music & Coffee", "artist_id": 3, "artist_name": "The Wild Sax Band", "artist_image_link": "https://images.unsplash.com/photo-1558369981-f9ca78462e61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=794&q=80", "start_time": "2035-04-08T20:00:00.000Z" }, { "venue_id": 3, "venue_name": "Park Square Live Music & Coffee", "artist_id": 3, "artist_name": "The Wild Sax Band", "start_time": "2035-04-15T20:00:00.000Z" }] shows = [] for row in data: shows.append( Show(venue_id=row['venue_id'], artist_id=row['artist_id'], start_time=row['start_time'])) db.session.add_all(shows)
def gen_many_shows(num_shows, start_time): artists = Artist.query.all() venues = Venue.query.all() artists_iter = iter(artists) venues_iter = iter(venues) shows = [] for i in range(1, num_shows): new_show = Show() new_show.artist_id = next(artists_iter).id new_show.venue_id = next(venues_iter).id new_show.start_time = start_time shows.append(new_show) db.session.add_all(shows) db.session.commit()
seeking_venue=False) artist_3 = Artist(name="The Wild Sax Band", city="San Francisco", state="CA", phone="432-325-5432", genres="Jazz, Classical", image_link="https://images.unsplash.com/photo-1558369981-f9ca78462e61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=794&q=80", seeking_venue=False) # db.session.add_all([artist_1,artist_2,artist_3]) # db.session.commit() print(Artist.query.all()) show_1 = Show(venue_id=4, artist_id=1, start_time="2019-05-21T21:30:00.000Z") show_2 = Show(venue_id=6, artist_id=2, start_time="2019-06-15T23:00:00.000Z") show_3 = Show(venue_id=6, artist_id=3, start_time="2035-04-01T20:00:00.000Z") show_4 = Show(venue_id=6, artist_id=3, start_time="2035-04-08T20:00:00.000Z") show_5 = Show(venue_id=6,
def insert_shows(): data = [ { "venue_id": 1, "venue_name": "The Musical Hop", "artist_id": 4, "artist_name": "Guns N Petals", "artist_image_link": "https://images.unsplash.com/photo-1549213783-8284d0336c4f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=300&q=80", "start_time": "2019-05-21T21:30:00.000Z", }, { "venue_id": 3, "venue_name": "Park Square Live Music & Coffee", "artist_id": 5, "artist_name": "Matt Quevedo", "artist_image_link": "https://images.unsplash.com/photo-1495223153807-b916f75de8c5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80", "start_time": "2019-06-15T23:00:00.000Z", }, { "venue_id": 3, "venue_name": "Park Square Live Music & Coffee", "artist_id": 6, "artist_name": "The Wild Sax Band", "artist_image_link": "https://images.unsplash.com/photo-1558369981-f9ca78462e61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=794&q=80", "start_time": "2035-04-01T20:00:00.000Z", }, { "venue_id": 3, "venue_name": "Park Square Live Music & Coffee", "artist_id": 6, "artist_name": "The Wild Sax Band", "artist_image_link": "https://images.unsplash.com/photo-1558369981-f9ca78462e61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=794&q=80", "start_time": "2035-04-08T20:00:00.000Z", }, { "venue_id": 3, "venue_name": "Park Square Live Music & Coffee", "artist_id": 6, "artist_name": "The Wild Sax Band", "artist_image_link": "https://images.unsplash.com/photo-1558369981-f9ca78462e61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=794&q=80", "start_time": "2035-04-15T20:00:00.000Z", }, ] try: for item in data: kwargs = { k: v for k, v in item.items() if k in Show.__table__.columns } row = Show(**kwargs) db.session.add(row) db.session.commit() except Exception as e: db.session.rollback() print("Error!!!! in show insertion") raise e finally: db.session.close()
website="https://www.gunsnpetalsband.com", seeking_venue=True, seeking_description= "Looking for shows to perform at in the San Francisco Bay Area!"), Artist( name="Matt Quevedo", city="New York", state="NY", phone="300-400-5000", genres=["Jazz"], image_link= "https://images.unsplash.com/photo-1495223153807-b916f75de8c5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80", facebook_link="https://www.facebook.com/mattquevedo923251523", seeking_venue=False), Artist( name="The Wild Sax Band", city="San Francisco", state="CA", phone="432-325-5432", genres=["Jazz", "Classical"], image_link= "https://images.unsplash.com/photo-1558369981-f9ca78462e61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=794&q=80", seeking_venue=False), Show(venue_id=1, artist_id=1, start_time="2019-05-21T21:30:00.000Z"), Show(venue_id=3, artist_id=2, start_time="2019-06-15T23:00:00.000Z"), Show(venue_id=3, artist_id=3, start_time="2035-04-01T20:00:00.000Z"), Show(venue_id=3, artist_id=3, start_time="2035-04-08T20:00:00.000Z"), Show(venue_id=3, artist_id=3, start_time="2035-04-15T20:00:00.000Z") ]) db.session.commit()
def add_initial_data(): # Add initial Venue datapoints venue1 = { "id": 1, "name": "The Musical Hop", "genres": "Jazz, Reggae, Swing, Classical, Folk", "address": "1015 Folsom Street", "city": "San Francisco", "state": "CA", "phone": "123-123-1234", "website": "https://www.themusicalhop.com", "facebook_link": "https://www.facebook.com/TheMusicalHop", "seeking_talent": True, "seeking_description": "We are on the lookout for a local artist to play every two weeks. Please call us.", "image_link": "https://images.unsplash.com/photo-1543900694-133f37abaaa5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=400&q=60" } venue2 = { "id": 2, "name": "The Dueling Pianos Bar", "genres": "Classical, R&B, Hip-Hop", "address": "335 Delancey Street", "city": "New York", "state": "NY", "phone": "914-003-1132", "website": "https://www.theduelingpianos.com", "facebook_link": "https://www.facebook.com/theduelingpianos", "seeking_talent": False, "image_link": "https://images.unsplash.com/photo-1497032205916-ac775f0649ae?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80" } venue3 = { "id": 3, "name": "Park Square Live Music & Coffee", "genres": "Rock n Roll, Jazz, Classical, Folk", "address": "34 Whiskey Moore Ave", "city": "San Francisco", "state": "CA", "phone": "415-000-1234", "website": "https://www.parksquarelivemusicandcoffee.com", "facebook_link": "https://www.facebook.com/ParkSquareLiveMusicAndCoffee", "seeking_talent": False, "image_link": "https://images.unsplash.com/photo-1485686531765-ba63b07845a7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=747&q=80" } artist1 = { "id": 4, "name": "Guns N Petals", "genres": "Rock n Roll", "city": "San Francisco", "state": "CA", "phone": "326-123-5000", "website": "https://www.gunsnpetalsband.com", "facebook_link": "https://www.facebook.com/GunsNPetals", "seeking_venue": True, "seeking_description": "Looking for shows to perform at in the San Francisco Bay Area!", "image_link": "https://images.unsplash.com/photo-1549213783-8284d0336c4f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=300&q=80" } artist2 = { "id": 5, "name": "Matt Quevedo", "genres": "Jazz", "city": "New York", "state": "NY", "phone": "300-400-5000", "facebook_link": "https://www.facebook.com/mattquevedo923251523", "seeking_venue": False, "image_link": "https://images.unsplash.com/photo-1495223153807-b916f75de8c5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80" } artist3 = { "id": 6, "name": "The Wild Sax Band", "genres": ["Jazz", "Classical"], "city": "San Francisco", "state": "CA", "phone": "432-325-5432", "seeking_venue": False, "image_link": "https://images.unsplash.com/photo-1558369981-f9ca78462e61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=794&q=80" } show_data = [{ "venue_id": 1, "artist_id": 4, "start_time": "2019-05-21T21:30:00.000Z" }, { "venue_id": 3, "artist_id": 5, "start_time": "2019-06-15T23:00:00.000Z" }, { "venue_id": 3, "artist_id": 6, "start_time": "2035-04-01T20:00:00.000Z" }, { "venue_id": 3, "artist_id": 6, "start_time": "2035-04-08T20:00:00.000Z" }, { "venue_id": 3, "artist_id": 6, "start_time": "2035-04-15T20:00:00.000Z" }] for venue in [venue1, venue2, venue3]: venue_record = Venue(**venue) db.session.add(venue_record) for artist in [artist1, artist2, artist3]: artist_record = Artist(**artist) db.session.add(artist_record) for show in show_data: show_record = Show(**show) db.session.add(show_record) db.session.commit()
"seeking_description": "The cutest and fastest hedgehog in the universe!" }) db.session.add(a1) db.session.add(a2) db.session.add(a3) db.session.add(a4) db.session.commit() #---------------------------------# # Add Shows #---------------------------------# from datetime import datetime show1 = Show(start_time=datetime(2020, 5, 21, 21, 30, 0)) show1.artist = a3 show1.venue = v1 show2 = Show(start_time=datetime(2022, 6, 15, 23)) show2.artist = a3 show2.venue = v1 show3 = Show(start_time=datetime(2019, 5, 1, 21, 30)) show3.artist = a1 show3.venue = v2 show4 = Show(start_time=datetime(2021, 10, 1, 21, 30)) show4.artist = a2 show4.venue = v1
address= "34 Whiskey Moore Ave", city= "San Francisco", state= "CA", phone= "415-000-1234", website= "https://www.parksquarelivemusicandcoffee.com", facebook_link= "https://www.facebook.com/ParkSquareLiveMusicAndCoffee", seeking_talent= False, image_link= "https://images.unsplash.com/photo-1485686531765-ba63b07845a7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=747&q=80" ) db.session.add(venue3) db.session.commit() ####### populate shows show1 = Show(id = 1,venue_id = 1 ,artist_id =1, start_time='2019-05-21T21:30:00.000Z') db.session.add(show1) db.session.commit() show2 = Show(id = 2,venue_id = 3 ,artist_id =2, start_time='2019-06-15T23:00:00.000Z') db.session.add(show2) db.session.commit() show3 = Show(id = 3,venue_id = 3 ,artist_id =3, start_time='2035-04-01T20:00:00.000Z') db.session.add(show3) db.session.commit() show4 = Show(id = 4,venue_id = 3 ,artist_id =3, start_time='2035-04-08T20:00:00.000Z') db.session.add(show4) db.session.commit()
from app import Venue, Artist, Show, db show1 = Show(start_time="2019-05-21T21:30:00.000Z") show1.venue = 1 show1.artist = 1 show2 = Show(start_time="2035-04-01T20:00:00.000Z") show2.venue = 3 show2.artist = 2 show3 = Show(start_time="2035-04-08T20:00:00.000Z") show3.venue = 3 show3.artist = 3 show4 = Show(start_time="2035-04-15T20:00:00.000Z") show4.venue = 3 show4.artist = 3 db.session.add(show1) db.session.add(show2) db.session.add(show3) db.session.add(show4) db.session.commit()
def main(): db.create_all() db.session.add( Venue( name='The Musical Hop', genres=['Jazz', 'Reggae', 'Swing', 'Classical', 'Folk'], address='1015 Folsom Street', city='San Francisco', state='CA', phone='123-123-1234', website='https://www.themusicalhop.com', facebook_link='https://www.facebook.com/TheMusicalHop', seeking_talent=True, seeking_description= 'We are on the lookout for a local artist to play every two weeks. Please call us.', image_link= 'https://images.unsplash.com/photo-1543900694-133f37abaaa5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=400&q=60', )) db.session.add( Venue( name='The Dueling Pianos Bar', genres=['Classical', 'R&B', 'Hip-Hop'], address='335 Delancey Street', city='New York', state='NY', phone='914-003-1132', website='https://www.theduelingpianos.com', facebook_link='https://www.facebook.com/theduelingpianos', seeking_talent=False, image_link= 'https://images.unsplash.com/photo-1497032205916-ac775f0649ae?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80', )) db.session.add( Venue( name='Park Square Live Music & Coffee', genres=['Rock n Roll', 'Jazz', 'Classical', 'Folk'], address='34 Whiskey Moore Ave', city='San Francisco', state='CA', phone='415-000-1234', website='https://www.parksquarelivemusicandcoffee.com', facebook_link= 'https://www.facebook.com/ParkSquareLiveMusicAndCoffee', seeking_talent=False, image_link= 'https://images.unsplash.com/photo-1485686531765-ba63b07845a7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=747&q=80', )) db.session.add( Artist( name='Guns N Petals', genres=['Rock n Roll'], city='San Francisco', state='CA', phone='326-123-5000', website='https://www.gunsnpetalsband.com', facebook_link='https://www.facebook.com/GunsNPetals', seeking_venue=True, seeking_description= 'Looking for shows to perform at in the San Francisco Bay Area!', image_link= 'https://images.unsplash.com/photo-1549213783-8284d0336c4f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=300&q=80', )) db.session.add( Artist( name='Matt Quevedo', genres=['Jazz'], city='New York', state='NY', phone='300-400-5000', facebook_link='https://www.facebook.com/mattquevedo923251523', seeking_venue=False, image_link= 'https://images.unsplash.com/photo-1495223153807-b916f75de8c5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80', )) db.session.add( Artist( name='The Wild Sax Band', genres=['Jazz', 'Classical'], city='San Francisco', state='CA', phone='432-325-5432', seeking_venue=False, image_link= 'https://images.unsplash.com/photo-1558369981-f9ca78462e61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=794&q=80', )) db.session.add( Show(venue_id=1, artist_id=1, start_time='2019-05-21 09:30:00 PM')) db.session.add( Show(venue_id=3, artist_id=2, start_time='2019-06-15 11:00:00 PM')) db.session.add( Show(venue_id=3, artist_id=3, start_time='2021-04-01 08:00:00 PM')) db.session.add( Show(venue_id=3, artist_id=3, start_time='2021-04-08 08:00:00 PM')) db.session.add( Show(venue_id=3, artist_id=3, start_time='2021-04-15 08:00:00 PM')) db.session.commit() db.session.close()
def insert_shows(): show_1 = Show( venue_id=1, venue_name="The Musical Hop", venue_image_link= "https://images.unsplash.com/photo-1543900694-133f37abaaa5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=400&q=60", artist_id=4, artist_name="Guns N Petals", artist_image_link= "https://images.unsplash.com/photo-1549213783-8284d0336c4f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=300&q=80", start_time="2019-05-21T21:30:00.000Z", ) show_2 = Show( venue_id=3, venue_name="Park Square Live Music & Coffee", venue_image_link= "https://images.unsplash.com/photo-1485686531765-ba63b07845a7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=747&q=80", artist_id=5, artist_name="Matt Quevedo", artist_image_link= "https://images.unsplash.com/photo-1495223153807-b916f75de8c5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80", start_time="2019-06-15T23:00:00.000Z", ) show_3 = Show( venue_id=3, venue_name="Park Square Live Music & Coffee", venue_image_link= "https://images.unsplash.com/photo-1485686531765-ba63b07845a7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=747&q=80", artist_id=6, artist_name="The Wild Sax Band", artist_image_link= "https://images.unsplash.com/photo-1558369981-f9ca78462e61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=794&q=80", start_time="2035-04-01T20:00:00.000Z", ) show_4 = Show( venue_id=3, venue_name="Park Square Live Music & Coffee", venue_image_link= "https://images.unsplash.com/photo-1485686531765-ba63b07845a7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=747&q=80", artist_id=6, artist_name="The Wild Sax Band", artist_image_link= "https://images.unsplash.com/photo-1558369981-f9ca78462e61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=794&q=80", start_time="2035-04-08T20:00:00.000Z", ) show_5 = Show( venue_id=3, venue_name="Park Square Live Music & Coffee", venue_image_link= "https://images.unsplash.com/photo-1485686531765-ba63b07845a7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=747&q=80", artist_id=6, artist_name="The Wild Sax Band", artist_image_link= "https://images.unsplash.com/photo-1558369981-f9ca78462e61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=794&q=80", start_time="2035-04-15T20:00:00.000Z", ) db.session.add_all([show_1, show_2, show_3, show_4, show_5]) db.session.commit()
def gen_specific_data(): artist0 = Artist() artist0.name = "Guns N Petals" artist0.genre.append(ArtistGenre(name="Rock N Roll")) artist0.city = "San Francisco" artist0.state = "CA" artist0.phone = "326-123-5000" artist0.website = "https://www.gunspetalsband.com" artist0.facebook_link = "https://www.facebook.com/GunsNPetals" artist0.seeking_venue = True artist0.seeking_description = "Looking for shows to perform at in the San Francisco Bay Area!" artist0.image_link = "https://images.unsplash.com/photo-1549213783-8284d0336c4f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=300&q=80" artist0.listed_time = datetime.datetime.utcnow() artist1 = Artist() artist1.name = "Matt Quevedo" artist1.genre.append(ArtistGenre(name="Jazz")) artist1.city = "New York" artist1.state = "NY" artist1.phone = "300-400-5000" artist1.facebook_link = "https://www.facebook.com/mattquevedo923251523" artist1.seeking_venue = False artist1.image_link = "https://images.unsplash.com/photo-1495223153807-b916f75de8c5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80" artist1.listed_time = datetime.datetime.utcnow() artist2 = Artist() artist2.name = "The Wild Sax Band" artist2.genre.append(ArtistGenre(name="Jazz")) artist2.genre.append(ArtistGenre(name="Classical")) artist2.city = "San Francisco" artist2.state = "CA" artist2.phone = "432-325-5432" artist2.seeking_venue = False artist2.image_link = "https://images.unsplash.com/photo-1558369981-f9ca78462e61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=794&q=80" artist2.listed_time = datetime.datetime.utcnow() artist3 = Artist() artist3.name = "Mo Jo Yo Jo" artist3.genre.append(ArtistGenre(name="Hip Hop Anonymous")) artist3.city = "Cool Cats" artist3.state = "CA" artist3.phone = "555-555-5000" artist3.website = "https://www.hoptothetop.com" artist3.facebook_link = "https://www.facebook.com/mojoyojo" artist3.seeking_venue = True artist3.seeking_description = "Looking for shows to perform at in Cool Cats California!" artist3.image_link = "https://images.unsplash.com/photo-1549213783-8284d0336c4f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=300&q=80" artist3.listed_time = datetime.datetime.utcnow() db.session.add(artist0) db.session.add(artist1) db.session.add(artist2) db.session.add(artist3) db.session.commit() venue0 = Venue() venue0.city = "San Francisco" venue0.state = "CA" venue0.phone = "123-123-1234" venue0.name = "The Musical Hop" venue0.genre.append(VenueGenre(name="Rock N Roll")) venue0.genre.append(VenueGenre(name="Jazz")) venue0.genre.append(VenueGenre(name="Classical")) venue0.address = "1015 Folsom Street" venue0.seeking_talent = True venue0.seeking_talent_desc = "We don't need talent, we need legends" venue0.listed_time = datetime.datetime.utcnow() venue1 = Venue() venue1.city = "San Francisco" venue1.state = "CA" venue1.phone = "415-000-1234" venue1.name = "Park Square Live Music & Coffee", venue1.genre.append(VenueGenre(name="Rap")) venue1.genre.append(VenueGenre(name="Rock N Roll")) venue1.genre.append(VenueGenre(name="Punk")) venue1.address = "34 Whiskey Moore Ave" venue1.seeking_talent = False venue1.listed_time = datetime.datetime.utcnow() venue2 = Venue() venue2.city = "New York" venue2.state = "NY" venue2.phone = "914-003-1132" venue2.name = "The Dueling Pianos Bar" venue2.genre.append(VenueGenre(name="Soul")) venue2.address = "335 Delancey Street" venue2.seeking_talent = True venue2.seeking_talent_desc = "Yo we need some talent in this hizouse" venue2.listed_time = datetime.datetime.utcnow() venue3 = Venue() venue3.city = "Oakland" venue3.state = "CA" venue3.phone = "415-555-5555" venue3.name = "Oakland Convention Center", venue3.genre.append(VenueGenre(name="Alternative")) venue3.address = "6824 Main St" venue3.seeking_talent = False venue3.listed_time = datetime.datetime.utcnow() db.session.add(venue0) db.session.add(venue1) db.session.add(venue2) db.session.add(venue3) db.session.commit() show0 = Show() show0.artist_id = Artist.query.first().id show0.venue_id = Venue.query.first().id show0.start_time = datetime.datetime.fromisoformat( '2020-04-05T21:30:00.000') db.session.add(show0) db.session.commit()
o.website = obj.get('website') o.facebook_link = obj.get('facebook_link') try: o.seeking_talent = obj['seeking_talent'] except: o.seeking_venue = obj['seeking_venue'] o.seeking_description = obj.get('seeking_description') o.image_link = obj['image_link'] for genre in obj['genres']: if genre in [g.value for g in GenreEnum]: if isinstance(o, Venue): g = VenueGenres(genre=genre) elif isinstance(o, Artist): g = ArtistGenres(genre=genre) o.genres.append(g) db.session.add(o) db.session.commit() for show in shows: v = db.session.query(Venue).filter( Venue.name == show['venue_name']).first() a = db.session.query(Artist).filter( Artist.name == show['artist_name']).first() t = show['start_time'] o = Show(venue=v, artist=a, starttime=t) db.session.add(o) db.session.commit()
db.session.add(genre) db.session.commit() for v in venues: venue = Venue(name=v['name'], address=v['address'], city=v['city'], state=v['state'], phone=v['phone'], website=v['website'], facebook_link=v['facebook_link'], seeking_talent=v['seeking_talent'], image_link=v['image_link'] ) db.session.add(venue) for vg in v['genres']: vg_id = Genre.query.filter_by(name=vg).first().id # print(vg_id.id) venue_genre = Venue_Genre(venue_id = i, genre_id = vg_id) db.session.add(venue_genre) i+=1 i = 1 for a in artists: artist = Artist(name=a['name'], city=a['city'], state=a['state'], phone=a['phone'], website=a['website'], seeking_venue=a['seeking_venue'], image_link=a['image_link'] ) db.session.add(artist) for ag in a['genres']: ag_id = Genre.query.filter_by(name=ag).first().id artist_genre = Artist_Genre(artist_id = i, genre_id = vg_id) db.session.add(artist_genre) i+=1 for s in shows: show = Show(artist_id = s['artist_id'], venue_id = s['venue_id'], start_time = s['start_time']) db.session.add(show) db.session.commit()
# "venue_name": "Park Square Live Music & Coffee", # "venue_image_link": "https://images.unsplash.com/photo-1485686531765-ba63b07845a7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=747&q=80", # "start_time": "2035-04-01T20:00:00.000Z" # } db.session.add(venue1) db.session.add(venue2) db.session.add(venue3) db.session.add(artist1) db.session.add(artist2) db.session.add(artist3) db.session.commit() show1 = Show(venue_id=venue1.id, artist_id=artist1.id, start_time="2019-05-21T21:30:00.000Z") show2 = Show(venue_id=venue2.id, artist_id=artist2.id, start_time="2019-06-15T23:00:00.000Z") show3 = Show(venue_id=venue2.id, artist_id=artist3.id, start_time="2035-04-01T20:00:00.000Z") show4 = Show(venue_id=venue2.id, artist_id=artist3.id, start_time="2035-04-08T20:00:00.000Z") show5 = Show(venue_id=venue2.id,
"artist_id": 6, "start_time": "2035-04-08T20:00:00.000Z" }, { "venue_id": 3, "artist_id": 6, "start_time": "2035-04-15T20:00:00.000Z" }] # ---------------------------------------------------------------- # Load Data into DB # ---------------------------------------------------------------- for v in venues_data: venue = Venue(id=v["id"], name=v["name"]) for key, value in v.items(): setattr(venue, key, value) db.session.add(venue) db.session.commit() for a in artists_data: artist = Artist(id=a["id"], name=a["name"]) for key, value in a.items(): setattr(artist, key, value) db.session.add(artist) db.session.commit() for s in shows_data: show = Show(venue_id=s["venue_id"], artist_id=s["artist_id"], start_time=s["start_time"]) db.session.add(show) db.session.commit()
from app import db, Venue, Artist, Show v1 = Venue(name='Dor Ri Mi', city='New York', state='NY', address='53', phone='24008200', genres='jazz', image_link='https://picsum.photos/200/300', facebook_link='https://www.facebook.com/HeshamAhmos', website_link='https://www.facebook.com/HeshamAhmos', seeking_talent=True, seeking_description='yes we do') a1 = Artist(name='GUNS N PETALS', city='San Francisco', state='CA', phone=' 326-123-5000', genres='ROCK N ROLL', image_link='https://picsum.photos/200/300', facebook_link='https://www.facebook.com/HeshamAhmos', website_link='https://www.facebook.com/HeshamAhmos', seeking_venue=True, seeking_description='yes we do') s1 = Show(start_time='')
name="The Wild Sax Band", location_id=1, phone="432-325-5432", image_link= "https://images.unsplash.com/photo-1558369981-f9ca78462e61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=794&q=80", seeking_venue=False) print("Add Artists") db.session.add(artist1) db.session.add(artist2) db.session.add(artist3) #Add shows show1 = Show(venue_id=1, artist_id=4, start_time=format_datetime("2019-06-15T23:00:00.000Z")) show2 = Show(venue_id=3, artist_id=5, start_time=format_datetime("2019-06-15T23:00:00.000Z")) show3 = Show(venue_id=3, artist_id=6, start_time=format_datetime("2035-04-01T20:00:00.000Z")) show4 = Show(venue_id=3, artist_id=6, start_time=format_datetime("2035-04-08T20:00:00.000Z")) show5 = Show(venue_id=3,
def main(): with open('seed_data.json') as json_file: data = json.load(json_file) # artists = map(artist_mapper, data['artists']) print("Seeding...") try: for artist in data['artists']: past_days = random.randrange(0, 20) created_at = datetime.now() - timedelta(days=past_days) artist_obj = Artist( name=artist['name'], genres=artist["genres"], city=artist["city"], state=artist['state'], phone=artist['phone'], website=artist['website'], facebook_link=artist['facebook_link'], seeking_venue=artist['seeking_venue'], seeking_description=artist['seeking_description'], image_link=artist['image_link'], created_at=created_at, ) db.session.add(artist_obj) db.session.commit() for venue in data['venues']: past_days = random.randrange(0, 20) created_at = datetime.now() - timedelta(days=past_days) venue_obj = Venue( name=venue['name'], genres=venue["genres"], city=venue["city"], state=venue['state'], address=venue['address'], phone=venue['phone'], website=venue['website'], facebook_link=venue['facebook_link'], seeking_talent=venue['seeking_talent'], seeking_description=venue['seeking_description'], image_link=venue['image_link'], created_at=created_at, ) db.session.add(venue_obj) for i in range(10): past_days = random.randrange(-3, 3) start_time = datetime.now() + timedelta(days=past_days) show_obj = Show( artist_id=random.randrange(1, 20), venue_id=random.randrange(1, 20), start_time=start_time, ) db.session.add(show_obj) db.session.commit() for i in range(10): past_days = random.randrange(-3, 3) duration = random.randrange(2, 20) start_time = datetime.now() + timedelta(days=past_days) end_time = start_time + timedelta(days=duration) show_obj = Show( artist_id=random.randrange(1, 20), venue_id=random.randrange(1, 20), start_time=start_time, ) db.session.add(show_obj) db.session.commit() print("Done seeding.") except: db.session.rollback() print(sys.exc_info()) print("Error seeding.") finally: db.session.close()
}, { "venue_id": 3, "artist_id": 6, "start_time": "2035-04-01T20:00:00.000Z" }, { "venue_id": 3, "artist_id": 6, "start_time": "2035-04-08T20:00:00.000Z" }, { "venue_id": 3, "artist_id": 6, "start_time": "2035-04-15T20:00:00.000Z" }) for s in shows: show = Show(**s) db.session.add(show) # Genres # ---------------------------------------------------------------- genres = ({ "genre": "Alternative" }, { "genre": "Blues" }, { "genre": "Classical" }, { "genre": "Country" }, { "genre": "Electronic"
city='Fakesville', state="CA", phone='555-555-5456', website='https://www.youtube.com/watch?v=dQw4w9WgXcQ', facebook_link='https://www.facebook.com/joeexotic', image_link="https://images.unsplash.com/photo-1549213783-8284d0336c4f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=300&q=80", seeking_venue=False, seeking_description='Fake it till you make it baby!' ) add_list = [venue, venue2, artist, artist2] [db.session.add(item) for item in add_list] db.session.commit() show = Show( start_time=datetime(2020, 4, 25, 20, 40, 19, 448277), artist_id=1, venue_id=1 ) show2 = Show( start_time=datetime(2020, 6, 25, 20, 40, 19, 448277), artist_id=2, venue_id=2 ) add_list = [show, show2] [db.session.add(item) for item in add_list] db.session.commit() db.session.close()