Skip to content

Instantly share code, notes, and snippets.

@imdkm
imdkm / GeniusMetaData.py
Last active February 15, 2024 20:17
getting every song's meta data from a certain artist with Genius API
# this code is inspired by Jon Evans' project.
# http://www.jw.pe/blog/post/quantifying-sufjan-stevens-with-the-genius-api-and-nltk/
import requests, json
from time import sleep
# constant values.
BASE_URL = "https://api.genius.com"
CLIENT_ACCESS_TOKEN = "<YOUR TOKEN HERE>"
ARTIST_NAME = "<ANY ARTIST NAME>"
import requests, csv
from bs4 import BeautifulSoup
from time import sleep
for year in range(1940,2017):
print("start scraping " + str(year) + "'s chart.")
# initialize and put header on the main 'chart' list.
chart = [["rank", "artist name", "song title"]]
import csv, os
from collections import Counter
# initialise a list and put header in it.
sheet = [["id","title","artist","running time","intro length","total number of elements","formal elements","song elements","movement","repetition","key changes","metric changes","title words count"]]
# change the working directory.
# given that you have a hieralchy like this.
# +- hoge
# +- dataset