Example #1
0
def insert_genres():
    genres = {
        "Jazz",
        "Reggae",
        "Swing",
        "Classical",
        "Folk",
        "R&B",
        "Hip-Hop",
        "Rock n Roll",
    }
    objects = [Genre(name=genre) for genre in genres]

    db.session.bulk_save_objects(objects)
    db.session.commit()
Example #2
0
from forms import *
from app import Genre, db

# if genres is empty, insert with some initial data
if not Genre.query.all():
    genres = [
        Genre(name='Alternative'),
        Genre(name='Blues'),
        Genre(name='Classical'),
        Genre(name='Country'),
        Genre(name='Electronic'),
        Genre(name='Folk'),
        Genre(name='Funk'),
        Genre(name='Hip-Hop'),
        Genre(name='Heavy Metal'),
        Genre(name='Instrumental'),
        Genre(name='Jazz'),
        Genre(name='Musical Theatre'),
        Genre(name='Pop'),
        Genre(name='Punk'),
        Genre(name='R&B'),
        Genre(name='Reggae'),
        Genre(name='Rock n Roll'),
        Genre(name='Soul'),
        Genre(name='Other')
    ]
    db.session.bulk_save_objects(genres)
    db.session.commit()
    print(f'The database has been initialized with genres')
else:
    print(f'Genres are already present in the database, Nothing is done')
Example #3
0
}, {
    "genre": "R&B"
}, {
    "genre": "Reggae"
}, {
    "genre": "Rock n Roll"
}, {
    "genre": "Soul"
}, {
    "genre": "Swing"
}, {
    "genre": "Other"
})

for g in genres:
    genre = Genre(**g)
    db.session.add(genre)

#  Genre Association Tables
#  ----------------------------------------------------------------

db_genres = Genre.query.all()
genre_dictionary = {}

for g in db_genres:
    genre_dictionary[g.genre] = g


def get_genre_list(genre_str_list):
    genre_list = []
    for genre_str in genre_str_list:
Example #4
0
  }, {
    "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-15T20:00:00.000Z"
  }]

db.drop_all()
db.create_all()

i = 1

for g in genres:
    genre = Genre(name=g)
    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
a = []
for i in dg:
    for j in i["genre"]:
        a.append(j)
#a = ['Adventure',' Family',' Fantasy',' Musical','Action',' Adventure',' Sci-Fi',' Drama',' War','Horror',' Mystery',' Thriller',' Horror','Drama',' Romance','Animation','Crime',' History',' Western',' Film-Noir','Thriller','Fantasy','Musical',' Comedy',' Documentary',' Music','Comedy','Short',' Action','Family',' Sport',' Crime','Mystery',' Short','Talk-Show',' Biography','Biography','Romance','Game-Show','Western','Documentary',' News',' Talk-Show','Adult','Film-Noir',' Reality-TV']
#initializing Genre class before commiting
_genre = {}

try:
    db.create_all()
except Exception as e:
    print(e)
    pass

for i in a:
    df = {i: Genre(which_genre=i)}
    _genre.update(df)
#initializing Movie class and adding to session ready for commit
for i in _raw_data:
    kl = Movie(name=i["name"],
               director=i["director"],
               imdb_score=i["imdb_score"],
               popularity=i["99popularity"])
    db.session.add(kl)
#initializing Genre class and adding to session ready for commit
for p, q in _genre.items():
    db.session.add(q)
#commiting everything in session
db.session.commit()

#committing Relationship
Example #6
0
from app import db, Movie, Genre
from scrape import movie_dict, Genres

genres_dict = {}
ind = 1
# create genre table
for genre in Genres:
    genres_dict[genre] = str(ind)
    ind += 1
    to_add = Genre(name=genre)
    db.session.add(to_add)
    db.session.commit()

for key, value in movie_dict.items():
    director = value['director']
    #dire = director.split("\")[0]

    movie = Movie(name=value['name'],
                  released_year=value['released_year'],
                  director=director,
                  one_sentence=value['one_sentence'])
    genre_list = []
    for genre in value['genres']:
        id_table = int(genres_dict[genre])
        item = Genre.query.filter_by(id=id_table).one_or_none()
        genre_list.append(item)
    #print(len(genre_list))
    movie.genres = genre_list
    db.session.add(movie)
    db.session.commit()
from app import db, ArtistGenre, VenueGenre, Genre, format_datetime

# genre1 = Genre(name='Jazz')
# genre2 = Genre(name='Reggae')
# genre3 = Genre(name='Swing')
# genre4 = Genre(name='Classical')
# genre5 = Genre(name='Folk')
# genre6 = Genre(name='R&B')
# genre7 = Genre(name='Hip-Hop')
# genre8 = Genre(name='Rock n Roll')

genre9 = Genre(name='Alternative')
genre10 = Genre(name='Blues')
genre11 = Genre(name='Country')
genre12 = Genre(name='Electronic')
genre13 = Genre(name='Funk')
genre14 = Genre(name='Heavy Metal')
genre15 = Genre(name='Instrumental')
genre16 = Genre(name='Musical Theatre')
genre17 = Genre(name='Pop')
genre18 = Genre(name='Punk')
genre19 = Genre(name='Soul')
genre20 = Genre(name='Other')

print("add genres")
db.session.add(genre9)
db.session.add(genre10)
db.session.add(genre11)
db.session.add(genre12)
db.session.add(genre13)
db.session.add(genre14)