this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix quoting in library.tsv

+18 -5
+18 -5
backup.py
··· 11 11 from spotipy import Spotify, SpotifyOAuth 12 12 from subprocess import run 13 13 from pathlib import Path 14 + import re 14 15 import sys 15 16 import json 16 17 from rich import print ··· 33 34 ) 34 35 35 36 # Get tracks from API 36 - results = spotify.current_user_saved_tracks()['items'] 37 - # while results["next"]: 38 - # results = spotify.next(results) 39 - # tracks.extend(results["items"]) 37 + results = spotify.current_user_saved_tracks() 38 + """ Uncomment to fetch whole playlist (useful if it hasnt been synced up for a while) 39 + tracks = results['items'] 40 + while results["next"]: 41 + results = spotify.next(results) 42 + tracks.extend(results["items"]) 43 + """ 44 + 45 + # Fix quoting 46 + def fix_quoting(tracks): 47 + return { re.sub(r'"([^"]+)"', r'“\1”', track) for track in tracks } 48 + 40 49 41 50 # Get whole library 42 51 lib = list(library.read_text('utf8').splitlines()) 43 52 tracks, header = set(lib[1:]), lib[0] 53 + tracks = fix_quoting(tracks) 44 54 45 55 # Boil them down to (artists, title, album) 46 56 new_tracks = { ··· 49 59 t["track"].get("name", None), 50 60 # t["track"]["album"]["name"], 51 61 ]) 52 - for t in results 62 + for t in results['items'] 53 63 } - tracks 64 + 65 + new_tracks = fix_quoting(new_tracks) 66 + 54 67 55 68 if new_tracks: 56 69 print(f"⋆𐙚₊˚⊹♡ I got [bold][cyan]{len(new_tracks)}[reset] new tracks for ya 💖 ⋆౨ৎ˚⟡˖ ࣪")