Automating MakePlayingCards's online ordering system.
The below guide describes the procedure for setting up the web component. If you're here to download the clientside program, check the Releases tab.
requirements.txt
for the web application and local tool combined.
- Python3.8+
- Elasticsearch (probably easiest with Docker)
- A Google account
All steps with the prefix [PROD] are only needed if you are deploying this web app in a production environment. For running the application locally or for development, you can skip these steps.
- Clone this repo somewhere on your server/local computer. This will be referred to as the
$working_directory
. - If you are using an IDE to run the Django commands and are NOT using Windows: go to the
$working_directory/.run
directory and for each XML file delete the optionSDK_HOME
- Add the file
$working_director/MPCAutofill/MPCAutofill/.env
to edit any environment variables used in$working_directory/MPCAutofill/MPCAutofill/settings.py
.
IN ORDER TO RUN THE APP LOCALLY, YOU MUST ADDDJANGO_DEBUG=on
TO THE$working_director/MPCAutofill/MPCAutofill/.env
FILE - [PROD] In the
$working_director
, create a folder calledstaticroot
for static assets - [PROD] Deploy the Django project (I'm using DigitalOcean for Ubuntu) with a webserver (I'm using Apache) and serve static files with another webserver if you want (I was previously using nginx but now I just serve static files with Apache as well)
- Install Elasticsearch based on your OS, or with Docker (Installation Guide)
- It might make the most sense to unzip the Elasticsearch directory into your
$working_directory
- Optionally, add the executables to your PATH for easy terminal access (add
location-of-package/elasticsearch-<VERSION_NUM>/bin
to your PATH)
- It might make the most sense to unzip the Elasticsearch directory into your
- Run Elasticsearch
- Use the executable indicated in your OS's Installation Guide, optionally running it as a daemon.
- Test that Elasticsearch is running by querying the local instance. For example:
wget -qO- http://localhost:9200/
- Set up your Google Drive credentials using a Google Drive service account. For each step, only follow the instructions for the given section, then return and complete the next step. The linked tutorial is slightly out of date, but it is the most complete tutorial around.
- Step 1 - NOTE: The project name, product name, and Application type don't matter for just running the tool locally.
- Step 2 - NOTE: The JSON file you download at the end of this step is named something slightly different from what the application expects. Make sure to rename it.
- Rename the saved JSON file and move it to:
$working_directory/MPCAutofill
- Update the
$working_directory/MPCAutofill/drives.csv
spreadsheet with links to public Google Drives with MPC ready images - Install the main dependencies using a python virtual environment (this entire step is often automatically handled by your IDE)
- To initialize the environment, create the virtual environment library using
python3 -m venv $working_directory/venv
- Activate the environment using your OS specific command in the table found in this section of the docs: Scroll to the table
- In the
$working_directory
with the virtual environment active, run the commandpip3 install -r requirements.txt
to install all requirements listed in$working_directory/requirements.txt
- To initialize the environment, create the virtual environment library using
- In the
$working_directory
, run the commandpython manage.py migrate
to ensure the database tables reflect any Django model changes. - In the
$working_directory
, run the commandpython manage.py update_dfcs
to synchronise the double-faced cards table with Scryfall. - In the
$working_directory
, run the commandpython manage.py import_sources
to sync sources in$working_directory/MPCAutofill/drives.csv
to the database (optionally specifying a particular drive to sync with-d <drivename>
) - (Elasticsearch must be running for this script to work)
In the$working_directory
, run the commandpython manage.py update_database
to populate the database with cards from the sources loaded withimport_sources
- Optionally, create a cronjob to periodically run the database updater command, to ensure MPC Autofill reflects the current state of the linked Drives, and another cronjob to periodically synchronise the double-faced cards table with Scryfall:
0 0 * * * bash /root/mpc-autofill/update_database >> /root/db_update.txt 2>&1
0 0 * * SUN bash /root/mpc-autofill/sync_dfcs
- [PROD] Deploy two Google Script according to the code specified in
autofill.py
and adjust the URLs in that script to point to your GS endpoints