helpers.create_file_if_not_exists(artist_info_file_path)

artist_amount = 10000
counter = 0

covered_artists = helpers.read_lines_from_file(covered_artists_file_path)
artist_names = helpers.read_lines_from_file(artists_file_path)

covered_artists_file = open(covered_artists_file_path, "a")
artist_info_file = open(artist_info_file_path, "a")

covered_artists_amount = len(covered_artists)
found_artists_amount = helpers.file_len(artist_info_file_path)

helpers.startProgress("  Fetching next {0} Artists ".format(artist_amount),
                      "  Artists covered: " + str(covered_artists_amount),
                      "  Artists found: " + str(found_artists_amount))

for artist in artist_names:
    if counter >= artist_amount:
        break
    if artist in covered_artists:
        covered_artists.remove(artist)
        continue
    artist = artist.strip()
    query = artist.replace(" ", "+")
    query = urllib2.quote(query, safe='/')
    url = helpers.get_spotify_api_url("search",
                                      query=query,
                                      query_type="artist",
                                      limit="10")
    os.path.join(dir, "../../data/prepared/artist_info.txt"), "r")
for line in artist_info_file:
    line = ast.literal_eval(line)
    artists.append({"name": line["name"], "id": line["id"]})
artist_info_file.close()

covered_top_tracks_artists_file = open(covered_top_tracks_artists_file_path,
                                       'a')

artists_with_fetched_tracks_file = open(artists_with_fetched_tracks_file_path,
                                        'a')

covered_artists_amount = len(covered_artists)

helpers.startProgress(
    "  Fetching top tracks of next {0} Artists ".format(artist_amount),
    "  Artists covered so far: {0}".format(str(covered_artists_amount)))

for artist in artists:
    if counter >= artist_amount:
        break

    artist_name = artist["name"]

    if artist["name"] in covered_artists:
        covered_artists.remove(artist["name"])
        continue
    artist_id = artist["id"]

    url = helpers.get_spotify_api_url("artists",
                                      query=artist_id,
artist_amount = 10000
counter = 0

covered_artists = helpers.read_lines_from_file(covered_artists_file_path)

covered_artists_file = open(covered_artists_file_path, "a")
artist_tracks_features_file = open(artist_tracks_features_file_path, "a")

# Get all artists + tracks
artists = helpers.read_lines_from_file(artists_with_fetched_tracks_file_path)

covered_artists_amount = len(covered_artists)

helpers.startProgress(
    "  Fetching audio features of next {0} Artists ".format(artist_amount),
    "  Artists covered so far: \033[36m{0}\033[0m".format(
        str(covered_artists_amount)))

# loop over artists
for artist in artists:
    if counter >= artist_amount:
        break
    artist = ast.literal_eval(artist)
    artist_name = artist["artist"]["name"]
    artist_id = artist["artist"]["id"]
    track_ids = []

    if artist_name in covered_artists:
        covered_artists.remove(artist_name)
        continue
示例#4
0
covered_artists_amount = len(covered_artists)

with open(artist_fetch_last_page_file_path, 'r') as f:
    last_page = f.readline()

if last_page == "":
    last_page = 0
else:
    last_page = int(last_page)

page = last_page
pages = 500
limit = 10

helpers.startProgress(
    "  Fetching next {0}k Artists from Last FM Charts".format(pages),
    "  Artists covered so far: {0}".format(str(covered_artists_amount)),
)

artist_file = open(artist_file_path, "a")

while True:
    if page >= last_page + pages:
        break

    page += 1
    url = helpers.get_last_fm_api_url("chart.gettopartists",
                                      page=str(page),
                                      limit=str(limit))
    raw = helpers.make_api_call(url).read()
    data = json.loads(raw)
    artists = data["artists"]["artist"]