Milestone

Completed

Scoping out the API

Review the API documentation

Getting the data

The Last.fm API documentation is mostly quite straightforward. If you haven’t already, take a little time to look through the docs to see what’s available to use. Note that not everything you see on the Last.fm website will be accessible, some things are closed off and use custom APIs.

Where to begin?

Let’s create something simple, create a chart of my top 10 most played artists for the week and show many times I listened to that artist. Something similar to this:

image

Last.fm’s user.getWeeklyChartList method returns every week boundary a user has scrobbles for, and user.getWeeklyArtistChart returns the ranked artist chart for a given week. A small Python script (lastfm_weekly_pull.py) walks the full week list, pulls the top artists for each one (a --top-n flag, currently 10), and writes it all to a CSV, one row per artist per week, with a resume flag so an interrupted run doesn’t have to start over. Over ~20 years that’s about 1,120 weeks and 5,800 rows.

Where the data lives

The CSV sits in the repo at src/data/lastfm/weekly-top-artists.csv, checked in, not fetched, and a copy is served from /data/lastfm/weekly-top-artists.csv if you want to see the raw rows yourself. No API calls happen in the browser; re-running the pull script and swapping the file is the entire update flow.