Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Last.fm API Demo

Small project for exploring the Last.fm API: searching for an artist, pulling their top tracks, and looking up top artists by genre/tag.

Contents

  • toptracks.py — CLI script. Prompts for an artist name, resolves it to the closest matching artist via artist.search, then prints that artist's top 10 global tracks (playcount + unique listeners) via artist.getTopTracks.
  • lastfmdemo.ipynb — Jupyter notebook version of the same workflow, extended with:
    • a bar chart of top-track popularity (matplotlib)
    • results loaded into pandas DataFrames
    • a tag.getTopArtists lookup for top artists by genre

Requirements

  • Python 3
  • requests
  • For the notebook: pandas, matplotlib, numpy, and Jupyter
pip install requests pandas matplotlib numpy notebook

Setup

Both files call the Last.fm API with an API key. Get one from the Last.fm API account page, then set it as an environment variable and update the scripts to read it:

export LASTFM_API_KEY=your_key_here

Note: the API key is currently hardcoded in both toptracks.py and lastfmdemo.ipynb. Swap it for os.environ["LASTFM_API_KEY"] (or similar) before sharing or committing this project publicly.

Usage

CLI script

python toptracks.py

You'll be prompted to enter an artist name, then the script prints their top 10 tracks with playcount and listener counts.

Notebook

jupyter notebook lastfmdemo.ipynb

Run the cells in order. Key functions defined in the notebook:

  • search_artist(query) — resolve a search query to an artist name
  • get_top_tracks(artist_name) — print top 10 tracks and plot popularity as a bar chart
  • get_pandas(artist_name) — same as above, returned as a pandas.DataFrame
  • get_artists_by_top_genre(genre) — print top 10 artists for a given tag/genre

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages