Timelnr is a web app built in Pyton, Flask and Jinja. It was originally built for the Metal Gear Timeline. All the data from the timeline, as well as some styling information, is pulled from a Google Sheet (to facilitate community translation) and is automagically stored in an SQL database.
- Python 3.8
- A MySQL database
- A Docker environment
- Create a MySQL database, and set the correct credentials in the config file as explained in the section below
- Edit
start.sh
to configure your Docker environment (container name, and container port)` - Create a virtual environment (
python -m venv venv
) and activate it (. venv/bin/activate
) - Run
start.sh
to build the Docker image and let it run on your server - If everything works correctly, your instance of Timelnr should be now reacheable. You can safely
deactivate
the virtual environment
Open timelnr/config-sample.py
to configure Timelnr:
Description | Example | |
---|---|---|
SECRET_KEY | A key (byte format) you should generate yourself | b'MY_KEY_HERE' |
DB_HOST | Your database host address | http://localhost:3306 |
DB_NAME | Your database name | DB_Timelnr |
DB_USER | Your database username | myUser |
DB_PSW | Your database password | myPassword |
DB_TABLE_PREFIX | The table prefix to be used. Should end with an underscore | tln_ |
SPREADSHEET_ID | The ID of the Google sheet. Can be found in the URL bar | 1jfdwjDSe_djhJDGDHgfdsjgsdfhj_d3X0 |
SPREADSHEET_ENTRIES_RANGE | Range covering the timeline entries information | Entries!A3:V234 |
SPREADSHEET_LABELS_RANGE | Range covering the entry labels | Labels!A3:D13 |
SPREADSHEET_LANG_RANGE | Range covering the supported languages | Languages!A1:C15 |
IMPORTANT: Once you are done setting up the config file, rename it to
config.py
.
Here you can find a Useful Template. Feel free to make a copy and edit to your needs.
IMPORTANT: The sheet structure can be changed, as long as the data ranges defined in
timelnr/config.py
are correct.
The sheet should include three pages: Entries (the content of the timeline), Labels (management and styling), and Languages (list of supported languages).
The Entries page normally has the following structure:
ENGLISH | ITALIAN | ... | |||||||
---|---|---|---|---|---|---|---|---|---|
ID | YEAR | GAME | COLOR | SOURCE | IMG | VID | en | it | ... |
1 | 2001 | MGS2 | mgs2 | mgs2header.jpg | Snake is born | Nasce Snake | ... | ||
2 | Everyone loves him | Tutti lo amano | ... | ||||||
3 | 2012 | MGS4 | mgs4 | mgs4.png | Snake is dead | Muore Snake | ... | ||
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
- ID: entry ID. Must be unique
- YEAR: the year when a specific timeline entry happened
- GAME: title of the game. Should be used only for the first entry belonging to the game
- COLOR: name of the CSS class defined in the Labels page
- SOURCE: unused. Refers to the game that is source of that information
- IMG: name of the image relative to the entry. Stored in
timelnr/static/images/
- VID: unused. link to a YouTube video related to the entry
IMPORTANT: The first entry under every language column needs to be the relative language code (refer to this list), which should also match the one defined in the Languages page.
NOTE:
importer.py
pulls data from the Sheet via the Google API. To do this it relies on the dev credentials stored inservice_account.json
(which is not included in the repo). The file can be downloaded from your developer console following the instructions below.
- Go on the Google Developer Console
- Create a project, enable Drive and Sheets API, and create a Service Account
- Copy the generated email address, and add it to the list of users having access to your Sheet
- Generate a JSON key and download it as
service_account.json
in the project root - Simply run
python importer.py
- Edit the entries inside the Google Sheet
- Run
python importer.py
to rebuild the database
- Make sure that the relative column in the Entries sheet page has the right language code
- Make sure the Languages sheet page contains the new language. Currently the order needs to match the one in the Sheet.
- Run
python imorter.py
. This will recreate the SQL database - Create a virtual environment (
python -m venv venv
) and activate it (. venv/bin/activate
) - Rebuild docker image with
sh start.sh
- If everything works correctly, your instance of timlnr should now be reacheable, and you can now
deactivate
the virtual environment
- Edit the CSS files you want to change
- Edit the labels colors from the Labels page of the sheet
- Restart the Docker container with
docker restart timelnr
- If HTML files are changed, it's necessary to restart the Docker container (
docker restart timelnr
) - If only CSS files are changed, it's sufficient to just refresh the web page, deleting the cache (
Ctrl
+F5
)