Page MenuHomePhorge

testing.py
No OneTemporary

testing.py

#!/usr/bin/env python3
import csv
import sys
import tekore as tk
import pyml_config as config
import libmusicleague as lml
conf = (config.client_id, config.client_secret)
token = tk.request_client_token(*conf)
spotify = tk.Spotify(token)
print("Hello! Lets try some stuff.")
inputCSVpath = sys.argv[1]
with open(inputCSVpath, newline='', encoding='utf-8') as csvfile:
sniffed = csv.Sniffer().sniff(csvfile.readline())
csvfile.seek(0) # Seems dumb that this is necessary, maybe it's moving on thanks to the sniffing? But without this, DictReader will read the //second// line as the column headers
reader = csv.DictReader(csvfile, dialect=sniffed)
for row in reader:
#print(row)
for key in row.keys():
if key == "Spotify URI":
#print("Found a URI, specifically "+row["Spotify URI"])
trackid = tk.from_uri(row["Spotify URI"])[1]
#print(trackid)
track = spotify.track(trackid)
#print("That URI resolves to "+track.name+" by "+track.artists)
#print(track)
if len(track.artists) == 1:
for a in track.artists:
artist = a.asbuiltin().get("name")
else:
artistlist = []
for a in track.artists:
artistlist += [a.asbuiltin().get("name")]
artist = ", ".join(artistlist)
print(artist)

File Metadata

Mime Type
text/x-python
Expires
Mon, Aug 18, 1:07 PM (1 d, 5 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
184222
Default Alt Text
testing.py (1 KB)

Event Timeline