A Python CLI tool that generates a Spotify playlist of the top 50 songs from any week since October 1976. Enter a date, and the app scrapes the charts, finds each track on Spotify, and creates a ready-to-play playlist in your account — automatically.
- You enter a date (e.g.
1994-11-05) - The app scrapes musicchartsarchive.com for the top 50 singles chart of that week
- Each song is searched on the Spotify API by artist and title
- A new playlist is created in your Spotify account and all found tracks are added
- The playlist ID is saved to a local catalog (
playlists_catalog.json) for future reference
- Manual OAuth 2.0 Authorization Code Flow — implemented from scratch without third-party Spotify wrappers (see flow diagram)
- Automatic token refresh — persists access and refresh tokens to disk; refreshes silently when expired
- Retry logic — handles transient API errors (429, 502, 503, 504) with configurable retries and sleep delay
- Date normalization — adjusts any input date to the nearest Saturday (how weekly charts are indexed)
- Input validation — rejects future dates and dates before the chart archive's earliest records (October 1976)
- Local playlist catalog — saves playlist name → Spotify ID mappings to
playlists_catalog.json
- Python 3.12+
- A Spotify Developer account with an app created
git clone https://github.com/your-username/music-time-machine.git
cd spotify-time-machinepython -m venv venv
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windowspip install -r requirements.txtCreate a .env file in the project root:
SPOTIFY_CLIENT=your_client_id_here
SPOTIFY_SECRET=your_client_secret_here
In your Spotify Developer Dashboard, add the following Redirect URI to your app settings:
http://127.0.0.1:8888/callback
python main.pyOn first run, a browser window will open asking you to log in to Spotify and grant permission. After that, your token is saved locally and reused automatically.
Which year do you want to travel to? Type the date in this format YYYY-MM-DD: 1985-07-13
- Dates must be in
YYYY-MM-DDformat - Earliest supported date: October 1976
- Future dates are rejected
- Type
Xat the prompt to exit
- Dates must be in
YYYY-MM-DDformat, between October 1976 and today. TypeXto exit. - Songs not available on Spotify are skipped with a log message.
Access Token Loaded
1. ('Every Breath You Take', 'The Police')
2. ('Billie Jean', 'Michael Jackson')
...
Get song URI from spotify: 1/50
Get song URI from spotify: 2/50
...
Total songs URI: 47
Playlist added to the catalog!
Songs added!