Skip to content

Commit

Permalink
Fix give full path for file writing
Browse files Browse the repository at this point in the history
  • Loading branch information
xD3CODER committed Mar 29, 2019
1 parent b80c985 commit 655267c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions scrapper/getsongs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)

spotify_token = os.environ.get("SPOTIFY_TOKEN")
genius_access_token = os.environ.get("GENIUS_TOKEN")
artists_limit = os.environ.get("MAX_ARTISTS_SCRAPPING") or 10
Expand All @@ -28,6 +27,7 @@
topSongs = {}
artistsList = []


def request_spotify(path):
headers = {'Accept': 'application/json', 'Content-Type': 'application/json',
'Authorization': 'Bearer ' + spotify_token}
Expand All @@ -51,6 +51,7 @@ def request_spotify(path):

return r


# Get lyrics from Genius
def downloadLyrics(rapper):
rapperName = rapper["name"]
Expand Down Expand Up @@ -92,13 +93,12 @@ def downloadLyrics(rapper):
# Get playlist name for given playlist ID
def getPlaylistName(playlistId):
r = request_spotify("/playlists/" + playlistId + "?market=FR&fields=name")

return json.loads(r.text)["name"]


# Get artist informations
def getArtistInfos(artistId):
r = request_spotify("/artists/" + artistId)

return json.loads(r.text)


Expand All @@ -115,7 +115,6 @@ def getTrendyRappers(Playlists):
else:
limit = int(artists_limit)
r = request_spotify("/playlists/" + playlist + "/tracks?market=FR&limit=" + str(limit))

y = json.loads(r.text)
print("- ", getPlaylistName(playlist))
songs = y['items']
Expand Down Expand Up @@ -154,7 +153,9 @@ def scrapeSong(url):
# Write songs in file
def writeJson(jsonText):
global current_timestamp
with open('../dataset/lyrics-' + str(current_timestamp) + '.json', 'w') as f: # writing JSON object
path = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(path, '..', 'dataset/lyrics-' + str(current_timestamp) + '.json'),
'w') as f: # writing JSON object
json.dump(jsonText, f)


Expand Down

0 comments on commit 655267c

Please sign in to comment.