def get_songs_contains_key_words(self, keywords): yeganeh = Artist("mohsen", "yeganeh", datetime.datetime(1985, 4, 4)) khaje_amiri = Artist("ehsan", "kaje_amiri", datetime.datetime(1987, 5, 6)) songs_list = [ Song("akarin_bar", yeganeh, 123, SongTypes.pop, ["love"], None), Song("avalin_bar", khaje_amiri, 456, SongTypes.pop, ["love"], None) ] return songs_list
def artist_create(): artist_fields = artist_schema.load(request.json) new_artist = Artist() new_artist.name = artist_fields["name"] db.session.add(new_artist) db.session.commit() return jsonify(artist_schema.dump(new_artist))
def get_recommendation(self, playlist, recent_played, favorite_songs, favorite_albums, favorite_artists): yeganeh = Artist("mohsen", "yeganeh", datetime.datetime(1985, 4, 4)) khaje_amiri = Artist("ehsan", "kaje_amiri", datetime.datetime(1987, 5, 6)) songs_list = [ Song("akarin_bar", yeganeh, 123, SongTypes.pop, ["love"], None), Song("avalin_bar", khaje_amiri, 456, SongTypes.pop, ["love"], None) ] return songs_list
def artist_create(): #Create a new artist artist_fields = artist_schema.load(request.json) user_id = get_jwt_identity() user = User.query.get(user_id) if not user: return abort(401, description="Invalid user") new_artist = Artist() new_artist.artist_name = artist_fields["artist_name"] user.artists.append(new_artist) db.session.add(new_artist) db.session.commit() return jsonify(artist_schema.dump(new_artist))
def create(): form = ArtistForm(request.form) if form.validate_on_submit(): artist = Artist.create_from_form(form) if artist.insert(): return redirect(url_for('view_all_artists')) return render_template('forms/create_artist.html', form=form, notifications=fetch_unread_notifications()) return render_template('forms/create_artist.html', form=form, notifications=fetch_unread_notifications())
def save_song_to_db(song, db): """ Save song in database """ try: cursor = db.cursor() song_name = song.name artists = song.artists lyrics = song.lyrics album_name = song.album source = song.source poster_url = song.image_link mp3_links = song.mp3_links release_date = song.released_date youtube_id = song.youtube_id genres = song.genres album_id = None artist_ids = [] if album_name is not None: album_id = Album(album_name).insert(cursor).id for artist in (artists or [{'name': None, type: None}]): artist_id = Artist(artist['name'], artist['type']) \ .insert(cursor).id if artist['type'] == 'singer': artist_ids.append(artist_id) song_id = Song(song_name, lyrics, album_id, poster_url, release_date, youtube_id, artist_ids=artist_ids).insert(cursor).id for artist_id in artist_ids: SongArtist(song_id, artist_id).insert(cursor) if genres: for genre in genres: genre_id = Genre(genre).insert(cursor).id SongGenre(song_id, genre_id).insert(cursor) for quality in mp3_links: url = mp3_links.get(quality) Mp3s(song_id, url, source, quality).insert(cursor) db.commit() except IOError as error: print("Error while inserting new song", error)
def save_rankings_to_db(ranking, app): """ Save ranking in song_rankings table """ db = get_db(app) try: cursor = db.cursor() for rank in ranking: song_name = rank.name artist_name = rank.artist youtube_id = rank.youtube_id source = rank.source song_rank = rank.ranking week = rank.week genre = rank.genre artist_ids = [] for artist in artist_name: artist_id = Artist(artist, 'singer') \ .insert(cursor).id artist_ids.append(artist_id) song_id = Song(song_name, None, None, None, None, youtube_id, artist_ids=artist_ids).insert(cursor).id genre_id = Genre(genre).insert(cursor).id SongGenre(song_id, genre_id).insert(cursor) for artist_id in artist_ids: SongArtist(song_id, artist_id).insert(cursor) SongRankings( song_id, artist_id, source, song_rank, week, ).insert(cursor) except IOError as error: print('Error while inserting new ranking ', error) finally: db.commit() db.close()
def create_from_form(form): artist = Artist.get_by_name(form.artist_id.data) venue = Venue.get_by_name(form.venue_id.data) start_time = form.start_time.data if artist is None: form.artist_id.errors.append('Please enter a valid artist name') if venue is None: form.venue_id.errors.append('Please enter a valid venue name') if artist is not None and venue is not None: return (form, Show(artist_id=artist.id, venue_id=venue.id, start_time=start_time)) else: return (form, None)
def view_all(): searchQuery = '' items = Artist.query.order_by('name').all() if request.method == 'POST': searchQuery = request.form.get('searchQuery').lstrip().rstrip() items = Artist.search_for(searchQuery) else: if 'filter' in request.args: if request.args['filter'] == 'recent': items = Artist.fetch_recent( request.args.get('cpp', default=Artist.COUNT_PER_PAGE, type=int)) elif request.args['filter'] == 'top': items = Artist.fetch_top( request.args.get('cpp', default=Artist.COUNT_PER_PAGE, type=int)) return render_template('artists.html', data={ 'artists': items, 'searchQuery': searchQuery }, notifications=fetch_unread_notifications())
def get_all_artists(self): connection = sqlite3.connect("musicly.db") cur = connection.cursor() rs = None try: connection.row_factory = sqlite3.Row sql_statement = 'SELECT * FROM ARTIST' cur.execute(sql_statement) rs = cur.fetchall() except Exception as ex: print("There Is An Exception.") connection.close() list_of_artists = [] for row in rs: list_of_artists.append(Artist(row[0], row[1])) return list_of_artists
def seed_db(): from models.User import User # Importing the User model from models.Profile import Profile # Importing the Profile model from models.Playlist import Playlist from models.Track import Track from models.Album import Album from models.Artist import Artist from models.AlbumType import AlbumType from models.Collection import Collection from main import bcrypt # Hashing module for the passwords from faker import Faker # Importing the faker module for fake data import random # Importing random from the python standard library faker = Faker() users = [] albums = [] album_types = ["SINGLE", "ALBUM", "COMPILATION"] for i in range(5): # Do this 5 times user = User() # Create an user object from the User model if i == 0: user.is_admin = True else: user.is_admin = False user.email = f"test{i+1}@test.com" # Assign an email to the user object user.password = bcrypt.generate_password_hash("123456").decode( "utf-8") # Assign ta hashed password to the user object db.session.add(user) # Add the user to the db session users.append(user) # Append the user to the users list db.session.commit() # Commit the seeion to the db for i in range(5): profile = Profile() # Create a profile object from the Profile model profile.username = faker.first_name( ) # Add a username to the profile object profile.firstname = faker.first_name( ) # Add a firstname to the profile object profile.lastname = faker.last_name( ) # Add a lastname to the profile object profile.user_id = users[ i].id # Add a user_id to the profile object. This comes from real ids from the users list db.session.add(profile) # Add the profile to the session db.session.commit() # Commit the session to the database for i in range(10): album = Album() album.name = faker.catch_phrase() db.session.add(album) albums.append(album) db.session.commit() for at in album_types: album_type = AlbumType() album_type.name = at album_type.album_id = random.choice(albums).album_id db.session.add(album_type) db.session.commit() for i in range(5): artist = Artist() artist.name = faker.name_nonbinary() db.session.add(artist) db.session.commit() for i in range(20): track = Track() track.name = faker.file_name() track.track_num = random.choice(range(20)) track.album_id = random.choice(albums).album_id track.disc_num = 1 track.duration_ms = 2500 track.explicit = True playlist = Playlist() # Create a playlist object from Playlist model playlist.name = faker.catch_phrase() playlist.owner_id = random.choice(users).id playlist.collaborative = False playlist.public = True collection = Collection( ) # Create a playlist object from Playlist model collection.name = faker.catch_phrase() collection.owner_id = random.choice(users).id collection.collaborative = False collection.public = True db.session.add(track) db.session.add(playlist) db.session.add(collection) db.session.commit() print("Tables seeded") # Print a message to let the user know they
def seed_tables(): # User for i in range(10): user = User() user.id = i user.displayname = f"testuser{i}" user.email = f"TestEmail{i}@test.com" user.username = f"TestUserName{i}" user.password = bcrypt.generate_password_hash("testpassword").decode("utf-8") db.session.add(user) db.session.commit() print("Seeded Table: user") # Artist artists = [] for i in range(10): artist = Artist() artist.name = f"TestArtistName{i}" db.session.add(artist) artists.append(artist) db.session.commit() print("Seeded Table: artist") # Image for i in range(20): image = Image() image.url = f"TestURL{i}" image.height = choice(range(600, 1200)) image.width = choice(range(600, 1200)) db.session.add(image) db.session.commit() print("Seeded Table: images") def moods_table_creation(): moods = Moods() moods.amusement = choice(range(1, 101)) moods.joy = choice(range(1, 101)) moods.beauty = choice(range(1, 101)) moods.relaxation = choice(range(1, 101)) moods.sadness = choice(range(1, 101)) moods.dreaminess = choice(range(1, 101)) moods.triumph = choice(range(1, 101)) moods.anxiety = choice(range(1, 101)) moods.scariness = choice(range(1, 101)) moods.annoyance = choice(range(1, 101)) moods.defiance = choice(range(1, 101)) moods.feelingpumped = choice(range(1, 101)) db.session.add(moods) db.session.commit() return moods # Tracks for i in range(30): track = Tracks() track.trackname = f"TestTrackName{i}" track.artist_id = choice(artists).id track.moods_id = moods_table_creation().id track.trackurl = f"TestTrackURL{i}" db.session.add(track) db.session.commit() print("Seeded Table: tracks")
war = Keyword(name='War', events=[], users=violeta) sculpture = Keyword(name='Sculpture', events=[], users=violeta) emerging_artists = Keyword(name='Emerging artists', events=[], users=violeta) sound = Keyword(name='Sound', events=[], users=violeta) installation = Keyword(name='Installation', events=[], users=violeta) video = Keyword(name='Video', events=[], users=violeta) site_specific = Keyword(name='Site specific', events=[], users=violeta) abstract = Keyword(name='Abstract', events=[], users=violeta) drawing = Keyword(name='Drawing', events=[], users=violeta) van_gogh = Artist( name='Vincent Van Gogh', description= 'Vincent Willem van Gogh was a Dutch post-impressionist painter who is among the most famous and influential figures in the history of Western art.', image= 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Vincent_van_Gogh_-_Self-Portrait_-_Google_Art_Project_%28454045%29.jpg/220px-Vincent_van_Gogh_-_Self-Portrait_-_Google_Art_Project_%28454045%29.jpg', dob='30 March 1853', dod='29 July 1890') arbus = Artist( name='Diane Arbus', description= 'Diane Arbus was an American photographer. Arbus famously worked to normalize marginalized groups and highlight the importance of proper representation of all people. She worked with a wide range of subjects including members of the LGBTQ+ community, strippers, carnival performers, nudists, dwarves, children, mothers, couples, elderly people, and middle-class families.', image= 'https://upload.wikimedia.org/wikipedia/en/thumb/a/ac/Diane-Arbus-1949.jpg/220px-Diane-Arbus-1949.jpg', dob='March 14, 1923 ', dod='July 26, 1971') hefuna = Artist( name='Susan Hefuna', dob='1962', description=
def show(artist_id): schema = ArtistSchema() artist = Artist.get(id=artist_id) if not artist: abort(404) return schema.dumps(artist)
def add_new_artist(artist_name): date_of_birth = input('Enter date of birth: ') artist = Artist(artist_name, date_of_birth) artist_controller.add_artist(artist) view_artists()
def seed_db(): from models.Album import Album from models.Artist import Artist from models.User import User from models.Track import Track from models.Playlist import Playlist from models.SeasonalD import SeasonalD from models.Album_Artist_Association import album_artist_association_table as aaat from models.User_Playlist_Association import user_playlist_association_table as upat from main import bcrypt from faker import Faker import random faker = Faker() #Initial Setup users = [] art_alb_association_pairs = [] alb_tra_association_pairs = [] tra_pla_association_pairs = [] usr_pla_association_pairs = [] count_art_alb = [0] * 10 count_alb_art = [0] * 10 count_alb_tra = [0] * 10 count_tra_alb = [0] * 10 count_tra_pla = [0] * 10 count_pla_tra = [0] * 10 count_pla_usr = [0] * 10 count_usr_pla = [0] * 10 #Association Lists SETUP + Counts for i in range(1, 11): usr_int = random.randint(1, 10) pla_int = random.randint(1, 10) art_int = random.randint(1, 10) alb_int = random.randint(1, 10) tra_int = random.randint(1, 10) #Append Association List - Albums and Artists - don't enter duplicates while (art_int, alb_int) in art_alb_association_pairs: art_int = random.randint(1, 10) alb_int = random.randint(1, 10) #Append Association List - Users and Playlists - don't enter duplicates while (usr_int, pla_int) in usr_pla_association_pairs: usr_int = random.randint(1, 10) pla_int = random.randint(1, 10) #Add count both directions count_usr_pla[usr_int - 1] += 1 count_pla_usr[pla_int - 1] += 1 count_art_alb[art_int - 1] += 1 count_alb_art[alb_int - 1] += 1 art_alb_association_pairs.append((art_int, alb_int)) usr_pla_association_pairs.append((usr_int, pla_int)) #Seasonal Discounts for i in range(1, 5): seasonald = SeasonalD() seasonsname = {1: "Summer", 2: "Autumn", 3: "Spring", 4: "Winter"} seasonsfloat = {1: 15.0, 2: 20.0, 3: 25.0, 4: 30.0} seasonald.seasonald_title = seasonsname[i] seasonald.seasonald_offer = seasonsfloat[i] db.session.add(seasonald) db.session.commit() #Users/Playlists for i in range(1, 11): user = User() playlist = Playlist() playlist.playlist_title = faker.unique.catch_phrase() user.email = f"test{i}@test.com" user.password = bcrypt.generate_password_hash("123456").decode("utf-8") user.seasonal_offer = faker.random_int(min=1, max=4) db.session.add(user) db.session.add(playlist) users.append(user) db.session.commit() #Tracks for i in range(1, 11): track = Track() track.track_title = faker.unique.catch_phrase() track.track_duration = faker.random_int(min=120, max=480) db.session.add(track) db.session.commit() #for i in enumerate(SeasonalD().id): # seasonald = SeasonalD() # seasonald.seasonald_title = seasonsname[seasonald.id] # seasonald.seasonald_offer = seasonsfloat[seasonald.id] # db.session.commit() #playlist = db.session.query(Playlist).filter(Playlist.id==i+1).one() #Seasonal Discounts Update! #seasonald.seasonald_title = seasonsname[seasonald.id] #seasonald.seasonald_offer = seasonsfloat[seasonald.id] #db.session.commit() #Seasonal Discounts Update! #seasonald.seasonald_title = seasonsname[seasonald.id] #seasonald.seasonald_offer = seasonsfloat[seasonald.id] #db.session.commit() #Artists/Albums for i in range(1, 11): artist = Artist() album = Album() artist.user_id = random.choice(users).id artist.artist_name = faker.unique.name() album.album_title = faker.unique.catch_phrase() db.session.add(artist) db.session.add(album) db.session.commit() #FINAL COUNTS #Count Artist's Albums print(f'art_count: {count_art_alb}') for i, val in enumerate(count_art_alb): print(f'ind: {i} val: {val}') artist = db.session.query(Artist).filter(Artist.id == i + 1).one() artist.artist_s_albums_count = val db.session.commit() #Count Album's Artists print(f'alb_count: {count_alb_art}') for i, val in enumerate(count_alb_art): print(f'ind: {i} val: {val}') album = db.session.query(Album).filter(Album.id == i + 1).one() album.album_s_artists_count = val db.session.commit() #Count Album's Tracks print(f'pla_count: {count_pla_usr}') for i, val in enumerate(count_pla_usr): print(f'ind: {i} val: {val}') playlist = db.session.query(Playlist).filter(Playlist.id == i + 1).one() playlist.playlist_s_users_count = val db.session.commit() #Count User's playlists print(f'usr_count: {count_usr_pla}') for i, val in enumerate(count_usr_pla): print(f'ind: {i} val: {val}') user = db.session.query(User).filter(User.id == i + 1).one() user.user_s_playlists_count = val db.session.commit() #Count Playlist's Users print(f'pla_count: {count_pla_usr}') for i, val in enumerate(count_pla_usr): print(f'ind: {i} val: {val}') playlist = db.session.query(Playlist).filter(Playlist.id == i + 1).one() playlist.playlist_s_users_count = val db.session.commit() #create association tables db.session.execute(aaat.insert().values(art_alb_association_pairs)) db.session.execute(upat.insert().values(usr_pla_association_pairs)) db.session.commit() print("Tables seeded")
def index(): schema = ArtistSchema(many=True) artists = Artist.select() return schema.dumps(artists)