Code to play a radio based on a Bandcamp user’s wishlist and https://bc-explorer.app.
- Create a
virtualenv
(I used Python 3.9) and activate itvirtualenv <env_name> source <env_name>/bin/activate
- Install the requirements
pip install -r requirements.txt
and then:
pip install -e .
- Create a
.env
file
A.env
file is used to keep track of machine-specific variables. Create a.env
in the root of this project with the following values set:PROJECT_DIR=/path/to/bandcamp_suggestor/ # the path to this directory BANDCAMP_USER=username # your bandcamp username RASPBERRY_PI_USER=username # your raspberry pi username (optional)
To access these variables in python code run:
from decouple import config config("PROJECT_DIR")
from src.bandcamp_suggestor import BandcampSuggestor
bc_suggestor = BandcampSuggestor('<bandcamp_username>')
bc_suggestor.generate_suggestions()
will scrape the collection and wishlist items from bandcamp, use a randomly picked one to feed to bc-explorer, and then returns suggestions from bc-explorer.
To play the radio based on your bandcamp wishlist locally run the following:
python scripts/play_infinite_radio.py
To run the radio on raspberry pi startup do the following:
- Install `RPi.GPIO` on the pi
pip install RPi.GPIO==0.7.1
- Give this file execute permissions
chmod +x path/to/raspberry_pi_on_startup.sh
- Run the following on startup of raspberry pi (https://unix.stackexchange.com/questions/166473/debian-how-to-run-a-script-on-startup-as-soon-as-there-is-an-internet-connecti):
export $(cat /path/to/.env | xargs) # to get $PROJECT_DIR and $RASPBERRY_PI_USER bash -c "${PROJECT_DIR}scripts/raspberry_pi_on_startup.sh > /path/to/run.log 2>&1" # Start the radio and log