class Edit(QDialog, Ui_Edit): """ Class documentation goes here. """ def __init__(self, c, conn, path, song, parent=None): """ Set all LineEdits if they already exist """ QDialog.__init__(self, parent) self.setupUi(self) self.song = song infos = self.song.get_all() self.c = c self.conn = conn self.path = path self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) self.trackLE.setText(self.getValidString(infos['track'])) self.cdLE.setText(self.getValidString(infos['cd'])) self.bpmLE.setText(self.getValidString(infos['bpm'])) self.titleLE.setText(self.getValidString(infos['title'])) self.interpreterLE.setText(self.getValidString(infos['interpreter'])) self.composerLE.setText(self.getValidString(infos['composer'])) self.albuminterpreterLE.setText(self.getValidString(infos['albuminterpreter'])) self.albumLE.setText(self.getValidString(infos['album'])) self.yearLE.setText(self.getValidString(infos['year'])) self.commentTE.setText(self.getValidString(infos['comment'])) def get_infos(self): return unicode(self.trackLE.text()), unicode(self.cdLE.text()), unicode(self.bpmLE.text()), unicode(self.titleLE.text()), unicode(self.interpreterLE.text()), unicode(self.composerLE.text()), unicode(self.albuminterpreterLE.text()), unicode(self.albumLE.text()), unicode(self.yearLE.text()), unicode(self.commentTE.toPlainText()) def getValidString(self, value): if value: return QString(unicode(value)) else: return QString() @pyqtSignature("QAbstractButton*") def on_buttonBox_clicked(self, button): """ Slot documentation goes here. """ if button.text() == 'Save': self.accept() else: self.reject() @pyqtSignature("") def on_editGenreButton_clicked(self): """ Slot documentation goes here. """ self.gdlg = Genre(self.c, self.conn, self.path) self.gdlg.exec_()
def get_genre(self): conn = sqlite3.connect('db/musicaly.db') s = conn.execute("SELECT GENRE_ID from Genre_Song WHERE SONG_ID =?", (self.id, )) genre_id = s.fetchall() genres = [] for i in genre_id: new_genre = Genre() new_genre.load(i[0]) genres.append(new_genre.name) return genres
def load_from(data): if data["schema"] != DB_SCHEMA: return for d in data["genres"]: Genre.unpickle(d) for d in data["artists"]: Artist.unpickle(d) for d in data["albums"]: Album.unpickle(d) for d in data["tracks"]: Track.unpickle(d) for l in data["libraries"]: Library.unpickle(l)
def test_director_genre_actor(): # check_init director = Director("Christopher Nolan") actor = Actor("Chris Pratt") genre = Genre("Horror") print(director) print(actor) print(genre)
def find_genres(parent, list): genres = libraries.values()[0].get_library_client().get_genres(parent) for data in genres: genre = Genre(data) list.append(genre) genre_by_id[data["id"]] = genre genre_by_name[genre.name] = genre g_ids.add(data["id"]) g_names.add(genre.name) find_genres(data["id"], genre.children)
def __init__(self, path): self.path = path self.handle = None self.tables = { 'track': Track(), 'album': Album(), 'artist': Artist(), 'genre': Genre(), 'label': Label() } self.auto_create = True self.error = None
def findAll(table): cnx = connectToDatabase() cursor = createCursor(cnx) cursor.execute(findAllQuery(table)) results = cursor.fetchall() # liste de dictionnaires contenant des valeurs scalaires closeCursor(cursor) disconnectDatabase(cnx) if (table == "movies"): movies = [] for result in results: # result: dictionnaire avec id, title, ... movie = Movie( title=result['title'], original_title=result['original_title'], duration=result['duration'], release_date=result['release_date'], rating=result['rating'] ) movie.id = result['id'] movies.append(movie) return movies if (table == "people"): people = [] for result in results: # result: dictionnaire avec id, title, ... person = Person( imdb_id=result['imdb_id'], name=result['name'], ) person.id = result['id'] people.append(person) return people if (table == "genres"): genres = [] for result in results: # result: dictionnaire avec id, title, ... genre = Genre(name=result['name']) genre.id = result['id'] genres[genre.name] = genre return genres
class TestOneToManyRelationships(unittest.TestCase): global driver_1 driver_1 = Driver("Daniel", "fast and furious") global driver_2 driver_2 = Driver("Alice", "faster and furiouser") global passenger_1 passenger_1 = Passenger("Michael Scott", 38) global passenger_2 passenger_2 = Passenger("Anna", 25) global passenger_3 passenger_3 = Passenger("Katie", 20) global trip_1 trip_1 = Trip(driver_1, passenger_1) global trip_2 trip_2 = Trip(driver_1, passenger_2) global trip_3 trip_3 = Trip(driver_1, passenger_3) global trip_4 trip_4 = Trip(driver_2, passenger_3) global trip_5 trip_5 = Trip(driver_2, passenger_2) def test_passenger_property_methods(self): self.assertEqual(passenger_1._name, "Michael Scott") self.assertEqual(passenger_1.name, "Michael Scott") self.assertEqual(passenger_1._age, 38) self.assertEqual(passenger_1.age, 38) def test_driver_property_methods(self): self.assertEqual(driver_1._name, "Daniel") self.assertEqual(driver_1.name, "Daniel") self.assertEqual(driver_1._driving_style, "fast and furious") self.assertEqual(driver_1.driving_style, "fast and furious") def test_trip_property_methods(self): self.assertEqual(trip_1._driver, driver_1) self.assertEqual(trip_1.driver, driver_1) self.assertEqual(trip_1._passenger, passenger_1) self.assertEqual(trip_1.passenger, passenger_1) def test_trip_class_method(self): self.assertItemsEqual(Trip._all, [trip_1, trip_2, trip_3, trip_4, trip_5]) self.assertItemsEqual(Trip.all(), [trip_1, trip_2, trip_3, trip_4, trip_5]) def test_driver_instance_methods(self): self.assertItemsEqual(driver_1.trips(), [trip_1, trip_2, trip_3]) self.assertItemsEqual(driver_1.passengers(), [passenger_1, passenger_2, passenger_3]) self.assertEqual(driver_1.trip_count(), 3) def test_passenger_instance_methods(self): self.assertItemsEqual(passenger_2.trips(), [trip_2, trip_5]) self.assertItemsEqual(passenger_2.drivers(), [driver_1, driver_2]) self.assertEqual(passenger_2.trip_count(), 2) global artist_1 artist_1 = Artist("Lady Gaga") global artist_2 artist_2 = Artist("Vulfpeck") global genre_1 genre_1 = Genre("Pop") global genre_2 genre_2 = Genre("Indie") global genre_3 genre_3 = Genre("Alternative") global song_1 song_1 = Song("Joanne", artist_1, genre_1) global song_2 song_2 = Song("Conscious Club", artist_2, genre_2) global song_3 song_3 = Song("Back Pocket", artist_2, genre_1) global song_4 song_4 = Song("El Chepe", artist_2, genre_3) global song_5 song_5 = Song("Sinner's Prayer", artist_1, genre_3) def test_genre_property_methods(self): self.assertEqual(genre_1._name, "Pop") self.assertEqual(genre_1.name, "Pop") def test_artist_property_methods(self): self.assertEqual(artist_1._name, "Lady Gaga") self.assertEqual(artist_1.name, "Lady Gaga") def test_song_property_methods(self): self.assertEqual(song_1._name, "Joanne") self.assertEqual(song_1.name, "Joanne") self.assertEqual(song_1._artist, artist_1) self.assertEqual(song_1.artist, artist_1) self.assertEqual(song_1._genre, genre_1) self.assertEqual(song_1.genre, genre_1) def test_song_class_method(self): self.assertItemsEqual(Song._all, [song_1, song_2, song_3, song_4, song_5]) self.assertItemsEqual(Song.all(), [song_1, song_2, song_3, song_4, song_5]) def test_artist_instance_methods(self): self.assertItemsEqual(artist_1.songs(), [song_1, song_5]) self.assertItemsEqual(artist_1.genres(), [genre_1, genre_3]) def test_genre_instance_methods(self): self.assertItemsEqual(genre_3.songs(), [song_4, song_5]) self.assertItemsEqual(genre_3.artists(), [artist_1, artist_2])
movies.append(newMovie) except: continue #we do nothing, that means the movie is malformed genres = [] # Reverse everything; we want to know how many movies each genre has for mv in movies: for genre in mv.genres: found = False for g in genres: if genre == g.name: g.addMovie(mv) found = True if not found: newGenre = Genre(genre) newGenre.addMovie(mv) genres.append(newGenre) # Sort them by number of movies genres = sorted(genres, key=lambda x: x.movieCount, reverse=True) # We build some channels from the 10 heaviest genres channels = [] i=0 for genre in genres: newChannel = Channel(genre.name) for mv in genre.movies: newChannel.addMovie(mv) newChannel.buildSchedule(86400000) channels.append(newChannel)
def read_csv_file(self): with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile: movie_file_reader = csv.DictReader(csvfile) for row in movie_file_reader: self.movies.append(row['Title']) self.actors.append(row['Actors']) self.genres.append(row['Genre']) self.directors.append(row['Director']) self.year.append(int(row['Year'])) self.description.append(row['Description']) self.runtime.append(row['Runtime (Minutes)']) self.external_ratings.append(row['Rating']) self.votes.append(row['Votes']) self.metascores.append(row['Metascore']) self.revenues.append(row['Revenue (Millions)']) index = 0 for mov in self.movies: mov = mov.split(',') mov = " ".join(mov) movie = Movie(mov, self.year[index]) if movie not in self.dataset_of_movies: self.dataset_of_movies.append(movie) movie.description = self.description[index] movie.director = Director(self.directors[index]) for genre in self.genres[index].split(','): movie.add_genre(Genre(genre)) for actor in self.actors[index].split(','): movie.add_actor(Actor(actor)) if self.runtime == 'N/A': pass else: movie.runtime_minutes = int(self.runtime[index]) if self.external_ratings == "N/A": pass else: movie.external_rating = float( self.external_ratings[index]) if self.revenues[index] == "N/A": pass else: movie.revenue = float(self.revenues[index]) if self.metascores[index] == "N/A": pass else: movie.metascore = int(self.metascores[index]) else: pass index += 1 for actor in self.actors: list_actors = actor.split(',') for act in list_actors: act = act.split() act = " ".join(act) if Actor(act) not in self.dataset_of_actors: self.dataset_of_actors.append(Actor(act)) else: pass for genre in self.genres: list_genre = genre.split(',') for gen in list_genre: gen = gen.split() gen = " ".join(gen) if Genre(gen) not in self.dataset_of_genres: self.dataset_of_genres.append(Genre(gen)) else: pass for director in self.directors: list_directors = director.split(',') for dir in list_directors: dir = dir.split() dir = " ".join(dir) if Director(dir) not in self.dataset_of_directors: self.dataset_of_directors.append(Director(dir)) else: pass
def on_editGenreButton_clicked(self): """ Slot documentation goes here. """ self.gdlg = Genre(self.c, self.conn, self.path) self.gdlg.exec_()
import json from category import Category from database import Database from playlist import Playlist from track import Track from artist import Artist from genre import Genre from collections import Counter import matplotlib import matplotlib.pyplot as plt import numpy as np db = Database() genresByPopularity = list(Genre.getByPopularity(db)) playlists = Playlist.loadAll(db) '''playlistFollowers = [] for playlist in playlists: artistFollowers = [] for track in playlist.tracks: if track.artist1: artistFollowers.append(track.artist1.followers) if track.artist2: artistFollowers.append(track.artist2.followers) if track.artist3: artistFollowers.append(track.artist3.followers) playlistFollowers.append(np.mean(artistFollowers)) plt.plot([playlist.followers for playlist in playlists], playlistFollowers) '''
from fastapi import FastAPI import uvicorn from song import Song from artist import Artist from genre import Genre # init app = FastAPI(debug=True) song = Song() artist = Artist() genre = Genre() # Route @app.get("/") def say_hello(): return {"Welcome": "Spotify Aggergation"} @app.get("/songs/artist/{artist}") def get_songs_by_artist(artist: str, page: int = 0, size: int = 1): return song.songs_by_artist(artist)[page * size:(page + 1) * size] @app.get("/songs/year/{year}") def get_songs_by_year(year: int, page: int = 0, size: int = 1): return song.songs_by_year(year)[page * size:(page + 1) * size] @app.get("/artists/{genre}")