示例#1
0
def main():
    print("")

    global api, conn
    with conn.cursor() as cursor:
        cursor.execute("SET autocommit=1")

    genres = ["fifties", "sixties", "seventies", "eighties", "nineties"]
    i = 0
    while i < len(genres):
        try:
            result = api.search(genres[i], type="playlist", limit=50)
            playlist_find(result)
            i += 1
        except (OSError, requests.exceptions.ConnectionError, urllib3.exceptions.ProtocolError) as e:
            errorPrint(e)
            print("Restantando o programa e a conexao do spotify\n")
            api = api_setup()
            continue
        except pymysql.err.OperationalError as e:
            errorPrint(e)
            print("Restantando o programa e a conexao do mysql\n")
            conn = mysql_setup()
            continue
        except TypeError as e:
            errorPrint(e)
            print("Restantando o programa\n ")
            continue
        except (spotipy.client.SpotifyException) as e:
            errorPrint(e)
            print("Restantando o programa e a conexao do spotify\n")
            api = api_setup()
            continue
示例#2
0
def main():
    try:
        logger.info("Script iniciado")
        print("")

        global api, conn
        with conn.cursor() as cursor:
            cursor.execute("SET autocommit=1")

        keywords = ["eighties", "nineties", "60s", "70s", "80s", "90s", "00s", "10s", "60's", "70's", "80's", "90's", "00's", "10's"]
        i = 0
        while i < len(keywords):
            with conn.cursor() as cursor:
                try:
                    cursor.execute("SELECT * FROM Tag WHERE tag_name = '{}'".format(keywords[i]))
                    tag_select = cursor.fetchone()
                except pymysql.err.IntegrityError as e:
                    logger.critical("Nao foi dar select em tag\n{}\n".format(e))

                if tag_select is None:
                    try:
                        cursor.execute("INSERT INTO Tag (tag_name) VALUES (%s)", (keywords[i]))
                        print("Tag '{}' adicionado".format(keywords[i]))
                    except pymysql.err.IntegrityError as e:
                        logger.error("Nao foi possivel dar adicionar a tag {}\n{}\n".format(keywords[i], e))
                        pass

            try:
                result = api.search(keywords[i], type="playlist", limit=50)
                playlist_find(result, keywords[i])
                i += 1
            except (OSError, requests.exceptions.ConnectionError, urllib3.exceptions.ProtocolError) as e:
                logger.fatal("!! {}".format(e))
                errorPrint(e)
                print("Restantando o programa e a conexao do spotify\n")
                api = api_setup()
                continue
            except pymysql.err.OperationalError as e:
                logger.fatal("!! {}".format(e))
                errorPrint(e)
                print("Restantando o programa e a conexao do mysql\n")
                conn = mysql_setup()
                continue
            
            #except TypeError as e:
            #    errorPrint(e)
            #    print("Restantando o programa\n ")
            #    continue
            except (spotipy.client.SpotifyException, spotipy.oauth2.SpotifyOauthError) as e:
                logger.fatal("!! {}".format(e))
                errorPrint(e)
                print("Restantando o programa e a conexao do spotify\n")
                api = api_setup()
                continue
    finally:
        logger.info("Script terminado")
        logging.shutdown()
示例#3
0
def get_artist(artist_id):
    global db
    api = api_setup()

    artist = api.artist(artist_id)
    del artist["external_urls"]
    artist["followers"] = artist["followers"]["total"]
    get_genre(artist["genres"])
    #del artist["genres"]
    del artist["href"]
    del artist["images"]
    del artist["type"]
    del artist["uri"]
    name = artist["name"]
    popularity = artist["popularity"]
    followers = artist["followers"]

    db("INSERT INTO Artist (id_artist, artist_name, popularity, followers) "
       "VALUES (%s, %s, %s, %s)".format(artist_id, name, popularity,
                                        followers))

    for genre in artist["genres"]:
        db("INSERT INTO Genre_Artist (genre_name, id_artist) "
           "VALUES (%s, %s)".format(genre, artist_id))


#artist = get_artist("62GoYifV4njTdvS8lD2yYT")

#with open("artist.json", "w+") as fp:
#    json.dump(artist, fp, indent=4)
示例#4
0
def artist_loop(artist_list):
    api = api_setup()
    artists_id = []

    for artist_info in artist_list:
        artist_id = artist_info["id"]
        artists_id.append(artist_id)

        artist = api.artist(artist_id)

        del artist["external_urls"]
        artist["followers"] = artist["followers"]["total"]
        genre_insert(artist["genres"])

        #del artist["genres"]
        del artist["href"]
        del artist["images"]
        del artist["type"]
        del artist["uri"]
        name = artist["name"]
        popularity = artist["popularity"]
        followers = artist["followers"]

        with conn.cursor() as cursor:
            try:
                cursor.execute("INSERT INTO Artist (id_artist, artist_name, popularity, followers) "
                "VALUES (%s, %s, %s, %s)", (artist_id, name, popularity, followers))
            except pymysql.err.IntegrityError as e:
                print("Erro: não foi possivel adicionar o artista '{}'\n{}\n".format(name, e))
                return artists_id

        for genre in artist["genres"]:
            with conn.cursor() as cursor:
                try:
                    cursor.execute("INSERT INTO Genre_Artist (genre_name, id_artist) "
                    "VALUES (%s, %s)", (genre, artist_id))
                except pymysql.err.IntegrityError as e:
                    print("Erro: não foi possivel adicionar o genero do artista\n{}\n".format(e))

        return artists_id
示例#5
0
#https://api.spotify.com/v1/playlists/4LAe6LdE6xlKOW1KlESeaA/tracks

import json
from pprint import pprint
from setup import api_setup
import time
import datetime


def str_to_timestamp_parser(texto):
    texto = texto[0:10]
    return datetime.datetime.strptime(texto, "%Y-%m-%d").timestamp()


api = api_setup()

#track = api.track("https://api.spotify.com/v1/track/4tmwiN9YU7xMjh2hoqcVuI")
search = api.search("top 50s", limit=50)
print("")
#pprint(track["album"])
print("")
#pprint(playlist_tracks["items"][0]["track"])

#track_features = api.audio_features(7HB2Waepqi7Ht68ZLKV2C0)

nexte = api._get(search["tracks"]["next"])
next2 = api._get(nexte["tracks"]["next"])
next3 = api._get(next2["tracks"]["next"])
next4 = api._get(next3["tracks"]["next"])

with open("nexte.json", "w+") as fp: