def add_artist(art):
    # you don't need with con. THe insert_art method will handle the db connection
    art_1 = Artist( 1, 'L. S.', 'Lowry')
    art_2 = Artist(2,'Claude', 'Monet' )
    art_3 = Artist(3,'Vincent Van', 'Gogh')
    insert_art(art_1)
    insert_art(art_2)
    insert_art(art_3)
Exemple #2
0
def add_artist(art):
    with conn:

        art_1 = Artist(1, 'L. S.', 'Lowry')
        art_2 = Artist(2, 'Claude', 'Monet')
        art_3 = Artist(3, 'Vincent Van', 'Gogh')
        insert_art(art_1)
        insert_art(art_2)
        insert_art(art_3)
Exemple #3
0
    def test_only_available_artist_artworks_are_returned(self):
        # List of artists with unique IDs
        example_artist_list = [
            Artist('John', '*****@*****.**', 1),
            Artist('Gary', '*****@*****.**', 3),
            Artist('Paula', '*****@*****.**', 5)
        ]

        # add each to db
        for artist in example_artist_list:
            artwork_store._add_artist(artist)

        # list of artworks with availability statuses of True or False
        example_artwork_list = [
            Artwork('Pigeon Scape', 150, 1, True),
            Artwork('Tarnished Hallow', 75, 1, False),
            Artwork('Bog Keeper', 140, 1, True),
            Artwork('Dance Rush', 20, 1, True),
            Artwork('Patchwork Sammy', 85, 5, True),
            Artwork('Basked Valley', 560, 3, False),
            Artwork('Patchwork Sammy', 85, 4, True),
            Artwork('Baked Patty', 1600, 3, False)
        ]

        # add each artwork to db
        for art in example_artwork_list:
            artwork_store._add_artwork(art)

        # returned artworks with True status of availability based on given Artowrk ID foreign key to Artist ID primary key
        actual_available_artwork_id_1_list = artwork.get_all_artist_available_artwork(
            1)
        actual_available_artwork_id_3_list = artwork.get_all_artist_available_artwork(
            3)
        actual_available_artwork_id_5_list = artwork.get_all_artist_available_artwork(
            5)

        # what is expected from db when ran based on provided Artwork IDs
        expected_available_artwork_id_1_list = [
            Artwork('Pigeon Scape', 150, 1, True),
            Artwork('Bog Keeper', 140, 1, True),
            Artwork('Dance Rush', 20, 1, True)
        ]

        expected_available_artwork_id_3_list = []

        expected_available_artwork_id_5_list = [
            Artwork('Patchwork Sammy', 85, 5, True)
        ]

        # Checks that list of tuples are equivalent to each other
        self.assertListEqual(expected_available_artwork_id_1_list,
                             actual_available_artwork_id_1_list)
        self.assertListEqual(expected_available_artwork_id_3_list,
                             actual_available_artwork_id_3_list)
        self.assertEqual(expected_available_artwork_id_5_list,
                         actual_available_artwork_id_5_list)
Exemple #4
0
    def test_only_artworks_searched_by_given_id_are_returned(self):
        # List of artists with unique IDs
        example_artist_list = [
            Artist('John', '*****@*****.**', 1),
            Artist('Gary', '*****@*****.**', 3),
            Artist('Paula', '*****@*****.**', 5)
        ]

        # add each to db
        for artist in example_artist_list:
            artwork_store._add_artist(artist)

        # list of artworks assigned to artist IDs
        example_artwork_list = [
            Artwork('Pigeon Scape', 150, 1, True),
            Artwork('Tarnished Hallow', 75, 1, False),
            Artwork('Bog Keeper', 140, 1, True),
            Artwork('Dance Rush', 20, 1, True),
            Artwork('Patchwork Sammy', 85, 5, True),
            Artwork('Basked Valley', 560, 3, False),
            Artwork('Patchwork Sammy', 85, 4, True),
            Artwork('Baked Patty', 1600, 3, False)
        ]

        # add each artwork to db
        for art in example_artwork_list:
            artwork_store._add_artwork(art)

        # what is actually found in db based on artwork ID foreign key of Artist ID
        actual_artwork_id_1_list = artwork.get_artwork_by_id(1)
        actual_artwork_id_3_list = artwork.get_artwork_by_id(3)
        actual_artwork_id_5_list = artwork.get_artwork_by_id(5)

        # what is expected from db when ran based on provided Artwork IDs
        expected_artwork_id_1_list = [
            Artwork('Pigeon Scape', 150, 1, True),
            Artwork('Tarnished Hallow', 75, 1, False),
            Artwork('Bog Keeper', 140, 1, True),
            Artwork('Dance Rush', 20, 1, True)
        ]

        expected_artwork_id_3_list = [
            Artwork('Basked Valley', 560, 3, False),
            Artwork('Baked Patty', 1600, 3, False)
        ]

        expected_artwork_id_5_list = [Artwork('Patchwork Sammy', 85, 5, True)]

        # Checks that list of tuples are equivalent to each other
        self.assertListEqual(expected_artwork_id_1_list,
                             actual_artwork_id_1_list)
        self.assertListEqual(expected_artwork_id_3_list,
                             actual_artwork_id_3_list)
        self.assertEqual(expected_artwork_id_5_list, actual_artwork_id_5_list)
Exemple #5
0
def mainstream_simartists(mainstream_id):
    a = Artist(mainstream_id)
    sim_ids = a.relatedid
    ids = set(sim_ids)
    for i in sim_ids:
        sim = Artist(i)
        ids.update([_ for _ in sim.relatedid])
    final_ids = set()
    for i in ids:
        sim = Artist(i)
        final_ids.update([_ for _ in sim.relateduri])
    return final_ids
Exemple #6
0
def merge_info(prev_info, curr_info):
    prev_info = convert_to_dict(prev_info)
    curr_info = convert_to_dict(curr_info)

    all_info = []
    for artist, info in curr_info.items():
        if artist in prev_info:
            albums = list(set(prev_info[artist]['albums'] + info['albums']))
            all_info.append(Artist(artist, len(albums), albums))
        else:
            all_info.append(Artist(artist, info['numAlbums'], info['albums']))
    return all_info
Exemple #7
0
 def __init__(self):
     self.excel = Excel()
     self.path = 'output/features_by_artist.xls'
     self.genres = collections.defaultdict()
     self.artists = _graph.influencers.copy()
     self.similarity_matrix = []
     self.pool = []
     self.distance = ['L1', 'L2', 'Minkowski']
     genre_data = self.excel.load_sheet(self.path)
     for i in range(1, self.excel.__len__(genre_data)):
         record = self.excel.read_by_row(genre_data, i)
         artist_id, artist_name, genre_name, feature = int(record[0]), record[1], \
                                                           record[2], record[3:]
         if feature[0] == 0:
             continue
         if genre_name not in self.genres:
             self.genres[genre_name] = Genre(genre_name)
         if artist_id not in self.artists:
             self.artists[artist_id] = Artist(artist_id, artist_name,
                                              genre_name)
             self.genres[genre_name].num_of_inf += 1
             self.genres[genre_name].influencer_id.append(artist_id)
         self.genres[genre_name].num_of_artist += 1
         self.genres[genre_name].artist_id.append(artist_id)
         self.genres[genre_name].feature_matrix.append(feature)
Exemple #8
0
 def test_add_artist_no_name(self):
     #new artist data - no name
     name = 'Ryan'
     artist = Artist(name, '')
     with self.assertRaises(sqlite3.IntegrityError):
         artwork_db.insert_art(artist)
     con.close()
def find_or_create_artist(name):
    artists_names = [artist._name for artist in Artist._all]
    if name in artists_names:
        return Artist.find_by_name(name)
    else:
        artist = Artist(name)
        return artist
Exemple #10
0
def read_from_CSV():
    today = date.today()
    today_str = today.strftime('%y%m%d')
    today_filename = today_str + '.csv'

    path, dirs, files = next(os.walk('../data/'))
    prev_artist_info = []
    all_csv_files = []
    valid_prev_data = False

    # check for valid .csv file
    for file in files:
        if '.csv' in file:
            valid_prev_data = True
            all_csv_files.append(file.split('.')[0])

    all_csv_files = sorted(all_csv_files, reverse=True)

    # check previous file closest to today
    if valid_prev_data:
        with open('../data/' + all_csv_files[0] + '.csv') as csv_file:
            reader = csv.reader(csv_file)
            for row in reader:
                # ast converts string list to type list
                artist = Artist(row[0], row[1], ast.literal_eval(row[2]))
                prev_artist_info.append(artist)
    else:
        print('No data to read from')

    return prev_artist_info
Exemple #11
0
def search(artist_name):
    limit = 10
    search_results = []
    response = sp.search(q=artist_name, type='artist', limit=limit)
    
    for artist in response['artists']['items']:
        pair = (artist['name'], artist['uri'])
        search_results.append(pair)
    
    for i, pair in enumerate(search_results, 1):
        print(str(i) + ". " + pair[0])
    
    selection = click.prompt("Which artist would you like to explore?", default=1, type=int)
    
    if selection < 1 or selection > limit:
        raise click.BadParameter('selection must be between 1 and ' + str(limit))
    
    selected_artist = search_results[selection-1]
    name = selected_artist[0]
    uri = selected_artist[1]
    
    print("Finding collaborators with " + name + "...")
    artist_data = Artist(uri)
    for collab_uri in artist_data.collaborators:
        collab_name = sp.artist(collab_uri)['name']
        print("- " + collab_name)
Exemple #12
0
def main(args):
    model = ArtistVGG19(shape=(args.height, args.width, 3),
                        verbose=args.verbose)
    config = ArtistConfig(
        contest_path=os.path.join(args.content_path, args.content_img),
        content_layers=[2, 7, 12, 21, 30],
        content_layer_weights=[1 / 5., 1 / 5., 1 / 5., 1 / 5., 1 / 5.],
        style_path=os.path.join(args.style_path, args.style_img),
        style_layers=[23],
        style_layer_weights=[1],
        size=(args.height, args.width),
        alpha=args.alpha,
        beta=args.beta,
        gamma=args.gamma,
        lr=args.lr,
        n_iter=args.n_iter,
        noise_rate=args.noise_rate,
        optimizer='adam',
        debug=args.debug,
        verbose=args.verbose)

    artist = Artist(model=model)
    img = artist.transform(config=config)

    save_img(os.path.join('result', args.img_name + '.jpg'), img)

    plt.imshow(img)
    plt.show()
Exemple #13
0
    def setDB(self):


        mydb = mysql.connector.connect(
                     host="localhost",
                     user="******",
                     passwd="1110235361",
                     database="priotuli"
         )
        mycursor = mydb.cursor()
        mycursor.execute("SELECT name, password, usertype FROM user")
        myresult = mycursor.fetchall()
        print(myresult)
        mycursor.close()
        mydb.close()

        name = self.uname.text()
        pwd = self.passw.text()
        print(name, " ", pwd)
        for row in myresult:
            #print(row[2])
            if name == row[0] and pwd == row[1]:
                if row[2] == "normal":
                    print("noraml")
                    self.normalUser = QtWidgets.QMainWindow()
                    self.ui = Normal()
                    self.ui.setupUi(self.normalUser)
                    self.normalUser.show()
                if row[2] == "artist":
                    print("artist")
                    self.artistWindow = QtWidgets.QMainWindow()
                    self.ui = Artist()
                    self.ui.setupUi(self.artistWindow)
                    self.artistWindow.show()
    def add_related(self, id, depth):
        '''
        Add to _adjacency list _artists related to artist with name given by name parameter.

        Function sleeps with each call for 0.1s to avoid flooding Spotify API.

        Function searches id of artist by sending a query to API. Then is queries for 
        related _artists of artist with retreived id. Adds related _artists to to list of said artist.
        Adds new _artists to dict.

        :param id: id of artist
        :type id: string
        :param depth: number of iterations of getting related artists. Not equal to depth of network.
        :type depth: int
        :return
        '''
        try:
            related = self._client.artist_related_artists(artist_id=id)
            new_artists = [Artist(r, depth) for r in related['artists']]

            # Append related artists to artist with given id
            self._adjacency[id].extend([a.id for a in new_artists])

            new_artists = [a for a in new_artists if a.id not in self._artists]
            new_artists_dict = {a.id: a.get_dict() for a in new_artists}
            self._artists = {**self._artists, **new_artists_dict}

            for a in new_artists:
                if a.id not in self._adjacency:
                    self._adjacency[a.id] = [id]
            sleep(0.2)
        except excs.ApiError as e:
            print('Error')
            print(e.msg)
Exemple #15
0
    def test_all_artwork_associated_with_artist_id_is_returned(self):
        # List of artists with unique IDs
        example_artist_list = [
            Artist('John', '*****@*****.**', 1),
            Artist('Gary', '*****@*****.**', 3)
        ]

        # add each to db
        for artist in example_artist_list:
            artwork_store._add_artist(artist)

        # list of artworks assigned to artist IDs
        example_artwork_list = [
            Artwork('Pigeon Scape', 150, 1, True),
            Artwork('Tarnished Hallow', 75, 1, False),
            Artwork('Bog Keeper', 140, 1, True),
            Artwork('Dance Rush', 20, 1, True),
            Artwork('Patchwork Sammy', 85, 5, True),
            Artwork('Basked Valley', 560, 3, False),
            Artwork('Patchwork Sammy', 85, 4, True),
            Artwork('Baked Patty', 1600, 3, False)
        ]

        # add each artwork to db
        for art in example_artwork_list:
            artwork_store._add_artwork(art)

        # what is actually found in db based on artist ID foreign key
        actual_john_artwork_list = artwork.get_all_artist_artwork(1)
        actual_gary_artwork_list = artwork.get_all_artist_artwork(3)

        # what's expected from db when ran from John and Gary (artists)
        expected_john_artwork = [
            Artwork('Pigeon Scape', 150, 1, True),
            Artwork('Tarnished Hallow', 75, 1, False),
            Artwork('Bog Keeper', 140, 1, True),
            Artwork('Dance Rush', 20, 1, True)
        ]

        expected_gary_artwork = [
            Artwork('Basked Valley', 560, 3, False),
            Artwork('Baked Patty', 1600, 3, False)
        ]

        # Checks that list of tuples are equivalent to each other
        self.assertListEqual(expected_john_artwork, actual_john_artwork_list)
        self.assertListEqual(expected_gary_artwork, actual_gary_artwork_list)
Exemple #16
0
 def test_add_artist_no_email(self):
     #new artist data - no email. This test fails - check the constraints in your DB,
     # must provide email
     name = 'Ryan'
     artist = Artist(name, None)
     with self.assertRaises(sqlite3.IntegrityError):
         artwork_db.insert_art(artist)
     con.close()
 def test_to_and_from_str_with_albums(self):
     artist = Artist('artist name', 'country')
     first_album = Album('first album title', 2020)
     first_album.add(Song('first song title'))
     first_album.add(Song('second song title'))
     second_album = Album('second album title', 2021)
     second_album.add(Song('third song title'))
     assert Artist.from_string(str(artist)) == artist
Exemple #18
0
 def get_artist(self, id):
     print(f'calling Spotify to get artist with id of {id}')
     spotify_artist = self.sp.artist(id)
     artist = Artist()
     artist.id = spotify_artist['id']
     artist.name = spotify_artist['name']
     artist.genres = spotify_artist['genres']
     return artist
def create_artist():
    name, email = get_user_input_with_two('Please insert artist information.', 'Name: ', 'Email: ')
    exists = database_control.search_artist(name)
    if not exists:
        artist = Artist(name, email)
        database_control.create_artist(artist)
    else:
        print('Artist already exists')
 def _plot(self, f, a, b):
     artist = Artist(strategy=self.strategy)
     if type(a) in [tuple, list]:
         if len(a) == 2:
             artist.plot_2d(f, a, b)
         else:
             artist.scatter_plot_per_dimension()
     else:
         artist.plot_1d(f, a, b)
Exemple #21
0
    def __init__(self, name, year, artist=None):
        self.name = name
        self.year = year
        if artist is None:
            self.artist = Artist("Various Artists")
        else:
            self.artist = artist

        self.tracks = []
 def test_artist_with_multiple_albums(self):
     artist = Artist('artist name', 'country')
     artist.add_album(Album('first album title', 2020))
     artist.add_album(Album('second album title', 2020))
     expected_albums = [
         Album('first album title', 2020),
         Album('second album title', 2020)
     ]
     assert list(artist.get_albums()) == expected_albums
Exemple #23
0
def add_new_artist(artist_name):
    """adds new artist to db if they are not already in"""
    if controls_utils.artist_already_in_db(artist_name):
        print('This artist is already in database')

    else:
        artist_email = get_artist_email()
        new_artist = Artist(artist_name, artist_email)
        artwork_db.add_artist(new_artist)
 def test_sort_albums_by_most_recent(self):
     artist = Artist('artist name', 'country')
     artist.add_album(Album('first album title', 2020))
     artist.add_album(Album('second album title', 2021))
     expected_albums = [
         Album('second album title', 2021),
         Album('first album title', 2020)
     ]
     artist.sort_albums_by_date()
     assert list(artist.get_albums()) == expected_albums
Exemple #25
0
 def get_artist(self):
     if self.artist_type == "Artist":
         artist = Artist()
         artist.load(self.artist_id)
         return artist
     elif self.artist_type == "Band":
         band = Band()
         band.load(self.artist_id)
         return band
     else:
         return "unknown"
Exemple #26
0
 def get_featured(self):
     if self.ft_type == "Artist":
         artist = Artist()
         artist.load(self.ft_id)
         return artist
     elif self.ft_type == "Band":
         band = Band()
         band.load(self.ft_id)
         return band
     else:
         return "No"
    def test_add_artist_with_same_email_returns_false_and_raises_integrity_error(
            self):
        artist_one_example = Artist('Harry', '*****@*****.**', 3)
        artwork_store._add_artist(artist_one_example)

        same_artist_email = Artist('Potter', '*****@*****.**', 4)
        add_same_email = artwork_store._add_artist(
            same_artist_email)  # shouldn't be allowed to add duplicate email

        self.assertFalse(add_same_email)
        self.assertRaises(
            sqlite3.IntegrityError
        )  # should also raise IntegrityError upon adding second entry with same email

        expected_rows = [('Harry', '*****@*****.**', 3)
                         ]  # only first artist should be in db
        actual_rows = self.get_artist_data()

        # assertCountEqual will compare two iterables, e.g. a list of tuples returned from DB
        self.assertCountEqual(expected_rows, actual_rows)
 def run(self):
     for importer in self.importers:
         for row in importer:
             (id, title, source), artists = row
             print(f'Importing "{title}" from {source}')
             exh_node = self.graph.add(Exhibition(id, title, source))
             nodes = []
             for a in artists:
                 name, wikidata_id = a
                 node = self.graph.add(Artist(name, wikidataID=wikidata_id))
                 nodes.append(node)
             self.graph.add_edges(exh_node, nodes)
Exemple #29
0
 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
Exemple #30
0
 def get_artist(self, id, name=None):
     """
     Returns an Artist for the passed ID, associated with this API object. You'll need to call Artist.update_data()
     if the artist hasn't already been cached. This is done on demand to reduce unnecessary API calls.
     """
     id = int(id)
     if id in self.cached_artists.keys():
         artist = self.cached_artists[id]
     else:
         artist = Artist(id, self)
     if name:
         artist.name = name
     return artist