The Random Movie Selector application takes a Google Sheet with information of movies like title, release year, etc and the watch status (unwatched or watched), selects a random one and if it fits the mood it can be accept the watch status gets updated in the Google Sheet and a message is posted to a Slack channel.
I'm running this application on a Raspberry Pi 4 with a four inch touchscreen running Raspbian OS - yes a Raspberry Pi 4 is overkill for this application, but I'm using it for more stuff then just this application
To get this application up and running a few steps are required:
- Get a Google Sheets API-key
- Get a Slack token
- Set up the application
- Start watching
For each of these steps there will be a dedicated chapter below - except for the fourth one ;)
In the design folder I saved the affinity designer project and a svg of the logo I created for this application.
There is also a section about the Raspberry Pi with some additional set up information, if required.
I'm using Google Sheets as my collection tracking medium, because I can access it on any device, it has a create set of features and can easily be shared. In the past I used the scripting engine for Google Sheets but I was never really pleased with this setup as it was slow (might be because of sloppy coding on my part) - in the folder archive_script I have included my previous setup.
Every movie collection is unique and so the different fields that are tracked are different. This application is flexible enough that with minimal effort any information that is stored inside of Google Sheets can be used. BUT one column is needed for this application and that is a column that tracks the watch status. Also another limitation is that more than 26 columns aren't supported and as I'm using only eight there are no plans on changing that.
Let's get up and running with the API
- Go to https://console.developers.google.com
- Create a new project with a name like
- Search for the Google Sheets API and enable it
- On the page for the Google Sheets API click Create Credentials
- Set Up the OAuth consent screen by clicking on it in the side bar (Select External, Enter an App Name, user support email and email), under Scopes add the Google Sheets API with the endpoint /auth/spreadsheets, under Test Users add your own email (important use @googlemail.com)
- Then go to Credentials and click Create Credentials, Type: Desktop App and click through to the end
- Under OAuth 2.0 Client IDs you should be able to download the credentials, rename them to credentials.json and move them into the root directory for this application
Having a Slack workspace is amazing as it is an easy hub for project based communication and adding different services to communicate with it. Here I'm using it to keep track of the date on which I watched which movie (I know there is also Letterboxd.com for this but I don't have access to the API).
I'm using a private channel for this application but a public one works just as well:
- Log into the Slack workspace to which this application should write
- Go to https://api.slack.com/start/overview#creating
- Click the Create a Slack App button
- Enter the App name (e.g. Random Movie Selector) and select the Slack workspace
- Under OAuth & Permissions go to Bot Token Spaces > Add an OAuth Scope and enter chat:write
- Scroll back to the top, copy and save OAuth Token
- Click install to Workspace
- Go to the Slack workspace and add the bot to a channel
- Copy the channel id from the url https://app.slack.com/client/<workspace-id/<channel-id>
There are two additional steps that can be taken to make the Slack integration a bit more fancy - but they are completely optional. Go to https://api.slack.com/apps and select the Random Movie Selector, then on the Basic Information page scroll down to the section titled Display Information
- Add the Slack_App_Icon.png from the design folder as an App icon
- Enter a description like*: Reports the random movie that was selected for your viewing pleasure* - under short description
- Click the save changes button
Download the application from GitHub
git clone https://github.com/Criptic/random_movie_selector.git
Change into the application folder
cd random_movie_selector
Install the required packages for the application to run
npm install
Create the configuration.json file with the needed contents - replace <> with the corresponding information - here all the collected information needs to be filled in. The runsOnRaspberryPi is defaulted to false, if set to true it will shutdown the Raspberry Pi after having selected a random movie with the ok button
cat << EOF > configuration.json
{
"spreadsheetId": "<spreadsheetId>",
"sheetName": "<sheetName>",
"range": "<range>",
"watchedStatusColumn": "<watchedStatusColumn>",
"unwatchedSymbol": "<unwatchedSymbol>",
"watchedSymbol": "<watchedSymbol>",
"slackToken": "<slackToken>",
"slackChannelId": "<slackChannelId>",
"runsOnRaspberryPi": false
}
EOF
Add the credentials.json file to the root folder of this application. Search for the two comments (CUSTOMIZE HERE) in app.js and adapt it according to the structure of the provided Google Sheets.
The spreadsheet ID can be found in the URL bar if you have it open: https://docs.google.com/spreadsheets/d/\<ID>/edit The sheet name is the name of the Google Sheet that you see at the bottom The range is what contains the actual data, e.g. A:H - there is no need to add the row number The watched status column is the letter of the column which contains your marker if a movie is watched or not - e.g. G The unwachted symbol identifies movies that haven't yet been watched - e.g. - The watched symbol identifies movies that have already been watched - e.g. X
After all this start up the application for the first time
npm start
Open up localhost:3000 in the web browser and hit the button Refresh Data, go back to the shell, copy the URL into the web browser, authenticate with the Google Account which has access to the Google Sheet and copy the token back into the shell. Now the application set up and ready to go.
Attach the Raspberry Pi to a Monitor or ssh into the Raspberry Pi (get the IP address of the Pi either through the router or type hostname -I in the shell of the Raspberry Pi
ssh pi@<ip-address>
Install node.js & npm on the Pi via the shell
sudo apt-get update
sudo apt install nodejs npm
# Test that the nodejs version is greater then v15.5.0 (that's the version I used)
node -v
Change into the folder the application should be downloaded into (e.g. Documents)
cd <~/Documents>
Two things are needed for this application to be coming up when starting the Raspberry Pi. First the server needs to be started and second a browser with the URL to the application needs to be opened (I'm using the preinstalled Chromium browser in kiosk mode).
To get the server up and running I'm using the npm-module forever to register the application as a service
sudo npm install forever -g
sudo npm install forever-service -g
sudo forever-service install <service_name e.g random_movie_selector> -- script <path to app.js e.g /home/pi/Documents/random_movie_selector/app.js>
sudo service <service_name> start
And now start up the browser with the website opened up in a tab
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
/usr/bin/chromium-browser --kiosk --disable-restore-session-state http://localhost:3000
The only problem for me with this solution is, that I have to hit the refresh button because it takes a bit longer for the server to start up but I'm okay with this solution.