Пример #1
0
def pullSpotifyTracks(location,
                      filename,
                      tracks=[],
                      local_tracks=[],
                      album_info=False,
                      token=None,
                      sptpy=None):
    ## set spotify auth
    config = hlpr.loadFile("../config", "config.csv", True)
    if token is not None:
        sptpy = spotipy.Spotify(auth=token)
    sptpy = getSpotifyCred()
    ## load tracks in playlist
    in_tracks = hlpr.loadFile(location, filename)
    for track in in_tracks:
        if 'local' in track:
            local_tracks.append(track)
            continue
        track_id = stripSpotifyLink(track)
        track_data = pullSpotifyTrack(track_id, token=token, sptpy=sptpy)
        if album_info:
            album_data = pullSpotifyAlbum(track_data['spotify_album_id'],
                                          token=token,
                                          sptpy=sptpy)
            track_data['release_date'] = album_data['release_date']
            track_data['year'] = album_data['year']
        tracks.append(track_data)
    return tracks, local_tracks
Пример #2
0
def main():
    if len(sys.argv) > 1:
        in_file = sys.argv[1]
    else:
        in_file = "../input/input.txt"
    track_list = []
    local_tracks = []

    config = loadFile("../config", "config.csv", True)
    token = sptfy.authSpotipy()

    for line in fileinput.input(in_file):
        if "local" in line:
            local_tracks.append(line)
            continue
        track_id = sptfy.stripSpotifyLink(line)
        track_data = sptfy.pullSpotifyTrack(track_id, token = token)
        track_list.append(track_data)
    sorted_tracks = sorted(
        track_list,
        key = lambda x: float(x['popularity']),
        reverse = True
    )
    print "\n"
    for item in sorted_tracks:
        print str(item['popularity']) + " :: " + item['artist'] + \
            " - " + item['title']
    print "\n"
    for item in sorted_tracks:
        print "spotify:track:{}".format(item['spotify_id'].strip())
    for item in local_tracks:
        print item
    print "\n"
Пример #3
0
def main():

    if len(sys.argv) > 1:
        in_file = sys.argv[1]
    else:
        in_file = "../input/input.txt"

    token = sptfy.authSpotipy()

    for f in glob.glob("../output/*.txt"):
        os.remove(f)

    config = hlpr.loadFile("../config", "config.csv", True)
    token = sptfy.authSpotipy()

    for line in fileinput.input(in_file):
        track_id = line.split("/")[-1].strip()
        track_info = sptfy.pullSpotifyTrack(track_id, token=token)
        artist_id = track_info['spotify_artist_id']
        artist_name = track_info['artist']
        track_name = track_info['title']
        secondary_artist = track_info['secondary_artist']
        hlpr.sortGenres(artist_name,
                        artist_id,
                        track_name,
                        track_id,
                        secondary_artist,
                        token,
                        makePlaylists=True)
Пример #4
0
def pullSpotifyTracks(location, filename, tracks = [], local_tracks = [], album_info = False, token = None):
    ## load tracks in playlist
    in_tracks = hlpr.loadFile(location, filename)
    for track in in_tracks:
        if 'local' in track:
            local_tracks.append(track)
            continue
        track_id = stripSpotifyLink(track)
        track_data = pullSpotifyTrack(track_id, token = token)
        if album_info:
            album_data = pullSpotifyAlbum(track_data['spotify_album_id'], token = token)
            track_data['release_date'] = album_data['release_date']
            track_data['year'] = album_data['year']
        tracks.append(track_data)
    return tracks, local_tracks
Пример #5
0
def materias(update, context):
    comando = update.message.text
    if "@" in comando:
        nomeDaMateria = comando.partition("@")[0][1:]
    else:
        nomeDaMateria = comando[1:]

    caminhoArquivo = f"Files/{nomeDaMateria}.txt"

    try:
        mensagem = loadFile(caminhoArquivo)
    except FileNotFoundError:
        mensagem = "Desculpa, não tenho informação sobre essa matéria ainda\.\.\. Ou o meu programador é preguiçoso demais\. Pqp viu @pedropp98"

    chatId = update.message.chat_id
    messageId = update.message.message_id
    context.bot.sendMessage(chat_id=chatId,
                            text=mensagem,
                            reply_to_message_id=messageId,
                            parse_mode="MarkdownV2",
                            disable_web_page_preview=True)
Пример #6
0
def main():

    username = sys.argv[1]
    artist = sys.argv[2]
    title = sys.argv[3]
    if len(sys.argv) > 4:
        album = sys.argv[4]
    else:
        album = None

    config = hlpr.loadFile("../config", "config.csv", True)

    app = sptfy.authSpotify(config)
    app.run()

    sp = sptfy.getSpotifyCred(username, config)

    tracks = sptfy.searchSpotifyTrack(artist, title, album)

    sptfy.searchUserPlaylists(sp, username, tracks)
    print "\n"
Пример #7
0
def pullSpotifyTracks(location,
                      filename,
                      tracks=[],
                      local_tracks=[],
                      album_info=False,
                      token=None):
    ## load tracks in playlist
    in_tracks = hlpr.loadFile(location, filename)
    for track in in_tracks:
        if 'local' in track:
            local_tracks.append(track)
            continue
        track_id = stripSpotifyLink(track)
        track_data = pullSpotifyTrack(track_id, token=token)
        if album_info:
            album_data = pullSpotifyAlbum(track_data['spotify_album_id'],
                                          token=token)
            track_data['release_date'] = album_data['release_date']
            track_data['year'] = album_data['year']
        tracks.append(track_data)
    return tracks, local_tracks
Пример #8
0
def main():

    username = sys.argv[1]
    artist = sys.argv[2]
    title = sys.argv[3]
    if len(sys.argv) > 4:
        album = sys.argv[4]
    else:
        album = None

    config = hlpr.loadFile("../config", "config.csv", True)

    app = sptfy.authSpotify(config)
    app.run()

    sp = sptfy.getSpotifyCred(username, config)

    tracks = sptfy.searchSpotifyTrack(artist, title, album)

    sptfy.searchUserPlaylists(sp, username, tracks)
    print "\n"
Пример #9
0
def main():

    if len(sys.argv) > 1:
        in_file = sys.argv[1]
    else:
        in_file = "../input/input.txt"

    token = sptfy.authSpotipy()

    for f in glob.glob("../output/*.txt"):
        os.remove(f)

    config = hlpr.loadFile("../config", "config.csv", True)
    token = sptfy.authSpotipy()

    for line in fileinput.input(in_file):
        track_id = line.split("/")[-1].strip()
        track_info = sptfy.pullSpotifyTrack(track_id, token = token)
        artist_id = track_info['spotify_artist_id']
        artist_name = track_info['artist']
        track_name = track_info['title']
        secondary_artist = track_info['secondary_artist']
        hlpr.sortGenres(artist_name, artist_id, track_name, track_id,
                        secondary_artist, token, makePlaylists = True)
Пример #10
0
def main():

    ## which feature to sort on
    sort_col1 = raw_input(
        "\nEnter one of the following features to sort on: \
        \ntitle\nartist\nalbum\nduration\ntempo\ntime_signature\nkey\nmode \
        \nloudness\nacousticness\ndanceability\nenergy\ninstrumentalness \
        \nliveness\nspeechiness\nvalence\npopularity\nrelease_date\nyear\n\n"
    )
    ## ascending or descending (1 = ascending, 0 = descending)
    ascending1 = int(raw_input(
        "\nChoose sort order for this feature: \
        \n(0) descending\n(1) ascending\n\n"
    ))
    while ascending1 != 0 and ascending1 != 1:
        ascending1 = int(raw_input(
            "\nEnter either 0 or 1: \
            \n(0) descending\n(1) ascending\n\n"
        ))

    if sort_col1 in ["album", "artist", "tempo", "time_signature", "key",
                     "mode", "popularity", "release_date", "year"]:
        sort_col2 = raw_input(
            "\nIn case of ties what second feature would you like to sort on: \
            \ntitle\nartist\nalbum\nduration\ntempo\ntime_signature\nkey\nmode \
            \nloudness\nacousticness\ndanceability\nenergy\ninstrumentalness \
            \nliveness\nspeechiness\nvalence\npopularity\nrelease_date\nyear\n\n"
        )
        ## ascending or descending (1 = ascending, 0 = descending)
        ascending2 = int(raw_input(
            "\nChoose sort order for this feature: \
            \n(0) descending\n(1) ascending\n\n"
        ))
        while ascending2 != 0 and ascending2 != 1:
            ascending2 = int(raw_input(
            "\nEnter either 0 or 1: \
            \n(0) descending\n(1) ascending\n\n"
        ))
    else:
        sort_col2 = None
        ascending2 = 1
    print("")

    config = hlpr.loadFile("../config", "config.csv", True)
    token = sptfy.authSpotipy()

    if "popularity" in [sort_col1, sort_col2]:
        db, unfound_tracks = sptfy.pullSpotifyTracks('../input',
                                                     'input.txt',
                                                     token = token)
        df = pd.DataFrame.from_dict(db)
        db, unfound_tracks = hlpr.processInput(input_playlist = "input.txt")
        db = db.merge(df[["spotify_id", "popularity"]], on = "spotify_id")
    else:
        ## get subset of db based on input.txt
        db, unfound_tracks = hlpr.processInput(input_playlist = "input.txt")

    if sort_col1 not in db.columns:
        print("\nSort column '{}' not in database!").format(sort_col1)
        sys.exit()
    if sort_col2 is not None and sort_col2 not in db.columns:
        print("\nSort column '{}' not in database!").format(sort_col2)
        sys.exit()

    if sort_col2 is None:
        sorted_db = db.sort_values(by = sort_col1, ascending = ascending1)
    else:
        sorted_db = db.sort_values(by = [sort_col1, sort_col2],
                                   ascending = [ascending1, ascending2])
    sorted_tracks = [
        "spotify:track:{}".format(x[1]['spotify_id']).rstrip() \
        if len(x[1]['spotify_id']) < 36 else x[1]['spotify_id'].rstrip() \
        for x in sorted_db.iterrows()
    ]

    print("\n")
    print(sorted_db[["artist", "title"]])

    hlpr.writeTextFile(sorted_tracks, "../output", "sorted_playlist.txt")
    print("\n")
    print("\n".join(sorted_tracks))

    if len(unfound_tracks) > 0:
        print("\nAdd these local tracks wherever you want in the playlist:\n")
        print("\n".join(unfound_tracks))
Пример #11
0
def main():

    # ## load tracks in playlist
    fives = loadFile("input", "fives.txt")
    fours = loadFile("input", "fours.txt")
    threes = loadFile("input", "threes.txt")
    twos = loadFile("input", "twos.txt")
    ones = loadFile("input", "ones.txt")

    ## load database of song ratings
    db = loadFile("../Databases", "song_ratings_db.csv")
    album_ratings = loadFile("../Databases", "album_ratings_db.csv")

    config = loadFile("../config", "config.csv", True)
    token = sptfy.authSpotipy()

    rating = 0
    for ls in [ones, twos, threes, fours, fives]:
        ## playlists are looped in this order such that if a song is in multiple lists it's rating will end up being the highest one
        rating = rating + 1
        for song in ls:
            track_id, spotify_uri = sptfy.getSpotifyTrackIDs(song)
            if not lookupSongBySpotifyID(track_id, db):
                track = sptfy.pullSpotifyTrack(track_id, token=token)
                db = db.append([{
                    'spotify_id': track_id,
                    'artist': track['artist'],
                    'album': track['album'],
                    'spotify_album_id': track['spotify_album_id'],
                    'song': track['title'],
                    'rating': rating
                }])

    db = db.sort(['artist', 'album', 'rating'])
    saveDataFrame(db, "../Databases", "song_ratings_db.csv")

    for album in pd.unique(zip(db.artist, db.album)):
        artist = album[0]
        album = album[1]
        if not lookupAlbumBySpotifyID(album, album_ratings):
            album_id = pd.unique(db[db.artist == artist][db.album == album]
                                 ['spotify_album_id'])[0]
            album_data = sptfy.pullSpotifyAlbum(album_id, token=token)
            ratings = db[db.artist == artist][db.album ==
                                              album]['rating'].tolist()
            if len(ratings) < 3:
                ## don't make album ratings for singles
                continue
            score = 0
            countNot3 = len(np.where(r != 3))
            countMoreThan2 = len(np.where(r > 2))
            countMoreThan3 = len(np.where(r > 3))
            for r in ratings:
                if r == 5:
                    score = score + 100 * 1.0
                    scoreNot3 = score + 100 * 1.0
                elif r == 4:
                    score = score + 80 * 1.2
                    scoreNot3 = score + 80 * 1.2
                elif r == 3:
                    score = score + 60 * 1.0
                elif r == 2:
                    score = score + 40 * 1.2
                    scoreNot3 = score + 40 * 1.2
                elif r == 1:
                    score = score + 20 * 1.0
                    scoreNot3 = score + 20 * 1.0
            std = np.std(ratings)
            if std == 0.0:
                std = 0.25

            if countNot3 == 0:
                adjMean = 3
            else:
                adjMean = scoreNot3 / countNot3
            prop4or5 = countMoreThan3 / len(r)
            adj1 = (adjMean - 3) * prop4or5
            adj2 = adj1 + countMoreThan2 * 0.03

            score = np.mean(ratings) + adj2

            if prop4or5 == 0:
                adjSD = std * 0.05
            else:
                adjSD = std * prop4or5 / len(r)

            score = score - adjSD

            ## min possible score: (mean of 1-star)
            min1 = 1.0
            ## max possible score: Radiohead "OK Computer"
            max1 = 5.662521
            min2 = -1.0
            max2 = -0.125

            scaledScore = (score - min1) / (max1 - min1)
            ## transform (curves the linear scores to inflate higher scores and reduce lower)
            transformedScore = -1 * (8 ^ (-1 * scaledScore))
            scaledScore = (transformedScore - min2) / (max2 - min2)
            album_score = (round(scaledScore * 1000)) / 1.0

            if album_score > 1000:
                album_score = 1000

            if album_score >= 965:
                album_rating = 5.0
            elif album_score >= 890:
                album_rating = 4.5
            elif album_score >= 750:
                album_rating = 4.0
            elif album_score >= 690:
                album_rating = 3.5
            elif album_score >= 625:
                album_rating = 3.0
            elif album_score >= 420:
                album_rating = 2.5
            elif album_score > 325:
                album_rating = 2.0
            elif album_score > 235:
                album_rating = 1.5
            elif album_score >= 100:
                album_rating = 1.0
            elif album_score < 100:
                album_rating = 0.5
            album_ratings = album_ratings.append([{
                'spotify_album_id': album_id,
                'artist': artist,
                'album': album,
                'year': album_data['year'],
                'album_rating': album_rating,
                'album_score': album_score
            }])

    saveDataFrame(album_ratings, "../Databases", "album_ratings_db.csv")
Пример #12
0
def main(ags, explicit=False):

    if args.ultimatechart is not None:
        with open(args.ultimatechart, 'r') as f:
            ultimatechart = f.readlines()
    else:
        ultimatechart = None
    if args.billboardchart is not None:
        with open(args.billboardchart, 'r') as f:
            billboardchart = [line.rstrip() for line in f]
    else:
        billboardchart = None

    cleans = []
    explicits = []
    local_tracks = []

    config = loadFile("../config", "config.csv", True)
    token = sptfy.authSpotipy()

    cleans, local_tracks = sptfy.pullSpotifyTracks('../input',
                                                   'cleans.txt',
                                                   token=token)
    explicits, local_tracks = sptfy.pullSpotifyTracks(
        '../input',
        'explicits.txt',
        tracks=explicits,
        local_tracks=local_tracks,
        token=token)

    if explicit:
        # sort explicit list
        sorted_tracks = sorted(explicits,
                               key=lambda x: float(x['popularity']),
                               reverse=True)
    else:
        # sort explicit list
        sorted_tracks = sorted(explicits,
                               key=lambda x: float(x['popularity']),
                               reverse=True)
        # now replace explicits with cleans
        for e in explicits:  # replace explicit track href by the clean version's href
            for c in cleans:
                if e['artist'] in c['artist'] and e['title'][:3] in c[
                        'title'][:3]:  # compare artist name and first 4 characters of track name
                    e['spotify_id'] = c['spotify_id']

    print "\n"
    for item in sorted_tracks:
        print str(item['popularity']
                  ) + " :: " + item['artist'] + " - " + item['title']
    print "\n"
    for item in sorted_tracks:
        print "spotify:track:{}".format(item['spotify_id'].strip())
    for item in local_tracks:
        print item
    print "\n"

    if ultimatechart is not None or billboardchart is not None:
        print "Look into keeping the following songs in Airplay this week...\n"

    if ultimatechart is not None:
        nums = ('01', '02', '03', '04', '05', '06', '07', '08', '09') + tuple(
            str(x) for x in range(10, 101))
        uc = [item for item in ultimatechart if item.startswith(nums)]
        for item in sorted_tracks:
            if item['popularity'] < 75:
                artist = item['artist']
                title = item['title']
                artist = re.sub("&", "and",
                                re.sub(r'([^\s\w]|_)+', '', artist).lower())
                title = re.sub("&", "and",
                               re.sub(r'([^\s\w]|_)+', '', title).lower())
                for u in uc:
                    x = re.sub(r'([^\s\w]|_)+', '', re.sub("&", "and",
                                                           u)).lower()
                    if artist + " " in x:
                        artist_match = True
                    else:
                        artist_match = False
                    if title + " by" in x:
                        title_match = True
                    else:
                        title_match = False
                    xs = [i for i in x.split(" ")]
                    if title_match or (artist_match and any(
                        [True for t in title.split(" ") if t in xs])):
                        print str(
                            item['popularity']
                        ) + " :: " + item['artist'] + " - " + item['title']
                        break
    else:
        print "\nIf you want to compare to Ultimate Chart, please provide a txt version as an arg to --ultimatechart"

    if billboardchart is not None:
        for item in sorted_tracks:
            if item['popularity'] < 75:
                artist = item['artist']
                title = item['title']
                artist = re.sub("&", "and",
                                re.sub(r'([^\s\w]|_)+', '', artist).lower())
                title = re.sub("&", "and",
                               re.sub(r'([^\s\w]|_)+', '', title).lower())
                for u in billboardchart:
                    x = re.sub(r'([^\s\w]|_)+', '', re.sub("&", "and",
                                                           u)).lower()
                    if artist in x:
                        artist_match = True
                    else:
                        artist_match = False
                    if title in x:
                        title_match = True
                    else:
                        title_match = False
                    xs = [i for i in x.split(" ")]
                    if title_match or (artist_match and any(
                        [True for t in title.split(" ") if t in xs])):
                        print str(
                            item['popularity']
                        ) + " :: " + item['artist'] + " - " + item['title']
                        break
    else:
        print "\nIf you want to compare to Billboard Chart, please provide a txt version as an arg to --billboardchart\n"

    print "\n"
Пример #13
0
from helpers import loadFile

IDS = loadFile("Ignore/Groups.txt").split()
grupo_teste = [int(IDS[0])]
mat_discreta = [int(IDS[1])]
icc = [int(IDS[2])]
fisica = [int(IDS[3]), int(IDS[4])]
algoritmos = [int(IDS[4]), int(IDS[5])]
grupos_sala = [int(IDS[5]), int(IDS[6])]
grupos_permitidos = [grupo_teste, grupos_sala[0], grupos_sala[1]]
Пример #14
0
def main():

    track_list = hlpr.loadFile("../input", "input.txt")
    desired_len = int(
        input("\nHow many tracks would you like the playlist to be? "))
    num_to_drop = len(track_list) - desired_len
    sort_col1 = input("\nEnter one of the following features to sort on: \
        \nacousticness\ndanceability\nenergy\nvalence\npopularity \
        \nrelease_date\nyear\n\n")
    ascending1 = int(
        input("\nChoose sort order for this feature: \
        \n(0) descending\n(1) ascending\n\n"))
    sort_col2 = input(
        "\nEnter another feature to sort on (blank to sort on one feature only): \
        \nacousticness\ndanceability\nenergy\nvalence\npopularity \
        \nrelease_date\nyear\n\n")
    if sort_col2 != '':
        ascending2 = int(
            input("\nChoose sort order for this feature: \
            \n(0) descending\n(1) ascending\n\n"))
    else:
        sort_col2 = None
        ascending2 = 1

    if "popularity" in [sort_col1, sort_col2]:
        db, unfound_tracks = sptfy.pullSpotifyTracks('../input', 'input.txt')
        df = pd.DataFrame.from_dict(db)
        db, unfound_tracks = hlpr.processInput(input_playlist="input.txt")
        db = db.merge(df[["spotify_id", "popularity"]], on="spotify_id")
    else:
        ## get subset of db based on input.txt
        db, unfound_tracks = hlpr.processInput(input_playlist="input.txt")

    if sort_col1 not in db.columns:
        print("\nSort column '{}' not in database!").format(sort_col1)
        sys.exit()
    if sort_col2 is not None and sort_col2 not in db.columns:
        print("\nSort column '{}' not in database!").format(sort_col2)
        sys.exit()

    sorted_db1 = db.sort_values(by=sort_col1, ascending=ascending1)
    if sort_col2 is not None:
        sorted_db2 = db.sort_values(by=sort_col2, ascending=ascending2)

    lst1 = sorted_db1.index.values
    lst2 = sorted_db2.index.values

    i = len(track_list) - num_to_drop
    remove = np.intersect1d(lst1[i:], lst2[i:])

    while len(remove) < num_to_drop:
        i -= 1
        remove = np.intersect1d(lst1[i:], lst2[i:])

    keep = [i for i in db.index if i not in remove]

    remove_db = db.loc[remove, ]
    keep_tracks = [
        "spotify:track:{}".format(x[1]['spotify_id']).rstrip() \
        if len(x[1]['spotify_id']) < 36 else x[1]['spotify_id'].rstrip() \
        for x in db.loc[keep, ].iterrows()
    ]
    remove_db = remove_db.sort_values(by=[sort_col1, sort_col2],
                                      ascending=[ascending1, ascending2])
    remove_tracks = [
        "spotify:track:{}".format(x[1]['spotify_id']).rstrip() \
        if len(x[1]['spotify_id']) < 36 else x[1]['spotify_id'].rstrip() \
        for x in remove_db.iterrows()
    ]

    print("\nThese songs will be removed:\n")
    pd.set_option('display.max_rows', None)
    print(remove_db[['artist', 'title', sort_col1, sort_col2]])
    print("")
    print("\n".join(remove_tracks))

    print("\n\nThese songs remain:\n")
    print("\n".join(keep_tracks))

    if len(unfound_tracks) > 0:
        print("\nAdd these local tracks wherever you want in the playlist:\n")
        print("\n".join(unfound_tracks))
Пример #15
0
def main(ags, explicit=False):

    if args.billboardchart is not None:
        with open(args.billboardchart, 'r') as f:
            billboardchart = [line.rstrip() for line in f]
    else:
        billboardchart = None

    cleans = []
    explicits = []
    local_tracks = []

    config = loadFile("../config", "config.csv", True)
    try:
        token = sptfy.authSpotipy()
    except:
        token = None
    sptpy = sptfy.getSpotifyCred()

    cleans, local_tracks = sptfy.pullSpotifyTracks('../input',
                                                   'cleans.txt',
                                                   sptpy=sptpy)
    explicits, local_tracks = sptfy.pullSpotifyTracks(
        '../input',
        'explicits.txt',
        tracks=explicits,
        local_tracks=local_tracks,
        sptpy=sptpy)

    if explicit:
        # sort explicit list
        sorted_tracks = sorted(explicits,
                               key=lambda x: float(x['popularity']),
                               reverse=True)
    else:
        # sort explicit list
        sorted_tracks = sorted(explicits,
                               key=lambda x: float(x['popularity']),
                               reverse=True)
        # now replace explicits with cleans
        for e in explicits:  # replace explicit track href by the clean version's href
            for c in cleans:
                if e['artist'] in c['artist'] and e['title'][:3] in c[
                        'title'][:3]:  # compare artist name and first 4 characters of track name
                    e['spotify_id'] = c['spotify_id']

    print("\n")
    for item in sorted_tracks:
        print(
            str(item['popularity']) + " :: " + item['artist'] + " - " +
            item['title'])
    print("\n")
    for item in sorted_tracks:
        print("spotify:track:{}".format(item['spotify_id'].strip()))
    for item in local_tracks:
        print(item)
        print("\n")

    if billboardchart is not None:
        print(
            "\nLook into keeping the following songs in Airplay this week...\n"
        )
        for item in sorted_tracks:
            if item['popularity'] < 75:
                artist = item['artist']
                title = item['title']
                artist = re.sub("&", "and",
                                re.sub(r'([^\s\w]|_)+', '', artist).lower())
                title = re.sub("&", "and",
                               re.sub(r'([^\s\w]|_)+', '', title).lower())
                for u in billboardchart:
                    x = re.sub(r'([^\s\w]|_)+', '', re.sub("&", "and",
                                                           u)).lower()
                    if artist in x:
                        artist_match = True
                    else:
                        artist_match = False
                    if title in x:
                        title_match = True
                    else:
                        title_match = False
                    xs = [i for i in x.split(" ")]
                    if title_match or (artist_match and any(
                        [True for t in title.split(" ") if t in xs])):
                        print(
                            str(item['popularity']) + " :: " + item['artist'] +
                            " - " + item['title'])
                        break
    else:
        print(
            "\nIf you want to compare to Billboard Chart, please provide a txt version as an arg to --billboardchart\n"
        )

    print("\n")
Пример #16
0
def main():

    track_list = hlpr.loadFile("../input", "input.txt")
    random.shuffle(track_list)
    hlpr.writeTextFile(track_list, "../output", "output.txt")
Пример #17
0
    #context.bot.send_message(chat_id=update.effective_chat.id, text=s)
    update.message.reply_text(s)'''


def loadFile(nomeArquivo):
    arquivo = open(nomeArquivo, encoding="UTF-8")
    linhasLidas = arquivo.readline()
    mensagem = ""
    while linhasLidas:
        mensagem += linhasLidas
        linhasLidas = arquivo.readline()
    arquivo.close()
    return mensagem


TOKEN = loadFile("Ignore/token.txt")
IDS = loadFile("Ignore/Groups.txt").split()
IDS = loadFile(".vscode/settings.json").split()
grupo_teste = [int(IDS[0])]
mat_discreta = [int(IDS[1])]
icc = [int(IDS[2])]
fisica = [int(IDS[3]), int(IDS[4])]
algoritmos = [int(IDS[4]), int(IDS[5])]
grupos_sala = [int(IDS[5]), int(IDS[6])]
grupos_permitidos = [grupo_teste, grupos_sala[0], grupos_sala[1]]


def separaProvas(materia, provas):
    splitProvas = provas.split("\n")
    textoFiltrado = f"{splitProvas[0]}\n"
    for i in splitProvas:
Пример #18
0
def main():

    # ## load tracks in playlist
    fives = loadFile("input", "fives.txt")
    fours = loadFile("input", "fours.txt")
    threes = loadFile("input", "threes.txt")
    twos = loadFile("input", "twos.txt")
    ones = loadFile("input", "ones.txt")

    ## load database of song ratings
    db = loadFile("../Databases", "song_ratings_db.csv")
    album_ratings = loadFile("../Databases", "album_ratings_db.csv")

    config = loadFile("../config", "config.csv", True)
    token = sptfy.authSpotipy()

    rating = 0
    for ls in [ones, twos, threes, fours, fives]:
        ## playlists are looped in this order such that if a song is in multiple lists it's rating will end up being the highest one
        rating = rating + 1
        for song in ls:
            track_id, spotify_uri = sptfy.getSpotifyTrackIDs(song)
            if not lookupSongBySpotifyID(track_id, db):
                track = sptfy.pullSpotifyTrack(track_id, token = token)
                db = db.append([{'spotify_id' : track_id, 'artist' : track['artist'], 'album' : track['album'], 'spotify_album_id' : track['spotify_album_id'], 'song' : track['title'], 'rating' : rating}])

    db = db.sort(['artist', 'album', 'rating'])
    saveDataFrame(db, "../Databases", "song_ratings_db.csv")

    for album in pd.unique(zip(db.artist, db.album)):
        artist = album[0]
        album = album[1]
        if not lookupAlbumBySpotifyID(album, album_ratings):
            album_id = pd.unique(db[db.artist == artist][db.album == album]['spotify_album_id'])[0]
            album_data = sptfy.pullSpotifyAlbum(album_id, token = token)
            ratings = db[db.artist == artist][db.album == album]['rating'].tolist()
            if len(ratings) < 3:
                ## don't make album ratings for singles
                continue
            score = 0
            countNot3 = len(np.where(r != 3))
            countMoreThan2 = len(np.where(r > 2))
            countMoreThan3 = len(np.where(r > 3))
            for r in ratings:
                if r == 5:
                    score = score + 100 * 1.0
                    scoreNot3 = score + 100 * 1.0
                elif r == 4:
                    score = score + 80 * 1.2
                    scoreNot3 = score + 80 * 1.2
                elif r == 3:
                    score = score + 60 * 1.0
                elif r == 2:
                    score = score + 40 * 1.2
                    scoreNot3 = score + 40 * 1.2
                elif r == 1:
                    score = score + 20 * 1.0
                    scoreNot3 = score + 20 * 1.0
            std = np.std(ratings)
            if std == 0.0:
                std = 0.25

            if countNot3 == 0:
                adjMean = 3
            else:
                adjMean = scoreNot3 / countNot3
            prop4or5 = countMoreThan3 / len(r)
            adj1 = (adjMean - 3) * prop4or5
            adj2 = adj1 + countMoreThan2 * 0.03

            score = np.mean(ratings) + adj2

            if prop4or5 == 0:
                adjSD = std * 0.05
            else:
                adjSD = std * prop4or5 / len(r)

            score = score - adjSD

            ## min possible score: (mean of 1-star)
            min1 = 1.0
            ## max possible score: Radiohead "OK Computer"
            max1 = 5.662521
            min2 = -1.0
            max2 = -0.125

            scaledScore = (score - min1) / (max1 - min1)
            ## transform (curves the linear scores to inflate higher scores and reduce lower)
            transformedScore = -1 * (8 ^ (-1 * scaledScore))
            scaledScore = (transformedScore - min2) / (max2 - min2)
            album_score = (round (scaledScore * 1000)) / 1.0

            if album_score > 1000:
	        album_score = 1000

            if album_score >= 965:
                album_rating = 5.0
            elif album_score >= 890:
                album_rating = 4.5
            elif album_score >= 750:
                album_rating = 4.0
            elif album_score >= 690:
                album_rating = 3.5
            elif album_score >= 625:
                album_rating = 3.0
            elif album_score >= 420:
                album_rating = 2.5
            elif album_score > 325:
                album_rating = 2.0
            elif album_score > 235:
                album_rating = 1.5
            elif album_score >= 100:
                album_rating = 1.0
            elif album_score < 100:
                album_rating = 0.5
            album_ratings = album_ratings.append([{'spotify_album_id' : album_id, 'artist' : artist, 'album' : album, 'year' : album_data['year'], 'album_rating' : album_rating, 'album_score' : album_score}])

    saveDataFrame(album_ratings, "../Databases", "album_ratings_db.csv")