A Python script that generates weekly music recommendations based on your Last.fm listening history. The script finds similar tracks to what you've been listening to recently but that you haven't heard before.
- Fetches your weekly listening history from Last.fm
- Finds similar tracks using the Last.fm API
- Filters out songs you've already listened to
- Saves a weekly list of music suggestions
- Can be run manually or automatically via GitHub Actions
- Python 3.11 or higher
- A Last.fm API key
- A Last.fm account with scrobbling history
-
Clone this repository
git clone https://github.com/yourusername/weekly-music-suggestions.git cd weekly-music-suggestions -
Install the required dependencies:
pip install -r requirements.txt
(Note: The requirements file needs to be created with
python-dotenvandrequests) -
Create a
.envfile in the project root with your Last.fm credentials:LASTFM_API_KEY=your_api_key_here LASTFM_USERNAME=your_username_here MAX_SUGGESTIONS=20 # Optional: maximum number of suggestions to generate
Run the script manually:
python script.pyThis will generate a file named suggestions_YYYY-MM-DD.txt containing your personalized music recommendations.
The repository includes a GitHub Actions workflow that runs the script automatically every Monday at 05:00 UTC. The results are automatically committed to the repository.
To set this up:
- Fork this repository
- Add your Last.fm API key and username as repository secrets:
- Go to your repository Settings > Secrets and variables > Actions
- Add a new repository secret named
LASTFM_API_KEYwith your API key - Add a new repository secret named
LASTFM_USERNAMEwith your Last.fm username
- The script fetches your weekly listening history from Last.fm
- For each track, it finds similar tracks using the Last.fm API
- It filters out any tracks you've already listened to
- It randomly selects up to
MAX_SUGGESTIONStracks from the results - The suggestions are saved to a dated text file
This project is open source and available under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.