adding dotenv to requirements, switching to using .env file for the settings
This commit is contained in:
parent
8068ed312b
commit
d07270ec9d
4
Makefile
4
Makefile
@ -1,4 +1,4 @@
|
||||
SHELL := /bin/bash
|
||||
#! make
|
||||
|
||||
default: run
|
||||
|
||||
@ -6,4 +6,4 @@ setup:
|
||||
@if [ ! -d ".venv" ]; then python3 -m venv .venv && .venv/bin/pip install -r requirements.txt; fi
|
||||
|
||||
run:
|
||||
@/bin/bash -c "set -a && source config.env && set +a && .venv/bin/python octomode.py"
|
||||
@.venv/bin/python octomode.py
|
||||
|
17
README.md
17
README.md
@ -83,18 +83,15 @@ You can clone this repository to run octomode on your own computer or server.
|
||||
|
||||
`make setup` (sets up a virtual environment and install the requirements, you only need to do this once)
|
||||
|
||||
Then you can configure your environment.
|
||||
`nano .env`
|
||||
|
||||
You can do this in two ways:
|
||||
|
||||
* by editing the `config.env` file
|
||||
* by storing the configuration settings as *environment variables* before running octomode:
|
||||
Configure your environment, save the following configuration settings as to a file called `.env`:
|
||||
|
||||
```
|
||||
$ export OCTOMODE_PORTNUMBER=XXX
|
||||
$ export OCTOMODE_PAD_URL=XXX
|
||||
$ export OCTOMODE_PAD_API_URL=XXX
|
||||
$ export OCTOMODE_PAD_API_KEY=XXX
|
||||
OCTOMODE_PORTNUMBER=XXX
|
||||
OCTOMODE_PAD_URL=XXX
|
||||
OCTOMODE_PAD_API_URL=XXX
|
||||
OCTOMODE_PAD_API_KEY=XXX
|
||||
```
|
||||
|
||||
- **OCTOMODE_PORTNUMBER**: *optional*, default: `5001`
|
||||
@ -106,7 +103,7 @@ $ export OCTOMODE_PAD_API_KEY=XXX
|
||||
|
||||
`make run` (runs the Flask application)
|
||||
|
||||
Open the application at port `5001`, for example: <http://localhost:5001> or <http://111.111.111.111:5001>.
|
||||
Open the application at port `5001`, for example: <http://localhost:5001> or <http://mydomainname.ext:5001>.
|
||||
|
||||
### Dependencies
|
||||
|
||||
|
15
octomode.py
15
octomode.py
@ -14,19 +14,8 @@ import pypandoc
|
||||
# To read the Markdown metadat
|
||||
import markdown
|
||||
|
||||
class Config(object):
|
||||
PORTNUMBER = int(os.environ.get('OCTOMODE_PORTNUMBER', 5001))
|
||||
PAD_URL = os.environ.get('OCTOMODE_PAD_URL', 'https://pad.vvvvvvaria.org')
|
||||
PAD_API_URL = os.environ.get('OCTOMODE_PAD_API_URL', 'https://pad.vvvvvvaria.org/api/1.2.15')
|
||||
PAD_API_KEY = os.environ.get('OCTOMODE_PAD_API_KEY', '')
|
||||
|
||||
APP = Flask(__name__)
|
||||
APP.config.from_object(Config)
|
||||
|
||||
if APP.config.get('OCTOMODE_PAD_API_KEY', '') == '':
|
||||
print("error: you must provide a value for OCTOMODE_PAD_API_KEY")
|
||||
print("error: e.g. export OCTOMODE_PAD_API_KEY=...")
|
||||
exit(1)
|
||||
APP.config.from_pyfile('settings.py')
|
||||
|
||||
# ---
|
||||
|
||||
@ -189,4 +178,4 @@ def pagedjs(name):
|
||||
|
||||
if __name__ == '__main__':
|
||||
APP.debug=True
|
||||
APP.run(host="0.0.0.0", port=APP.config["PORTNUMBER"], threaded=True)
|
||||
APP.run(host="0.0.0.0", port=APP.config["PORTNUMBER"], threaded=True)
|
@ -14,3 +14,4 @@ pypandoc==1.7.2
|
||||
typing-extensions==4.0.1
|
||||
urllib3==1.26.8
|
||||
zipp==3.7.0
|
||||
python-dotenv==0.21.0
|
17
settings.py
Normal file
17
settings.py
Normal file
@ -0,0 +1,17 @@
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables from the .env file
|
||||
load_dotenv()
|
||||
|
||||
# Bind them to Python variables
|
||||
PORTNUMBER = int(os.environ.get('OCTOMODE_PORTNUMBER', 5001))
|
||||
PAD_URL = os.environ.get('OCTOMODE_PAD_URL', 'https://pad.vvvvvvaria.org')
|
||||
PAD_API_URL = os.environ.get('OCTOMODE_PAD_API_URL', 'https://pad.vvvvvvaria.org/api/1.2.15')
|
||||
PAD_API_KEY = os.environ.get('OCTOMODE_PAD_API_KEY', '')
|
||||
|
||||
# Check if API key is provided
|
||||
if not PAD_API_KEY or PAD_API_KEY == "XXX":
|
||||
print("error: you must provide a value for OCTOMODE_PAD_API_KEY")
|
||||
print("error: e.g. export OCTOMODE_PAD_API_KEY=...")
|
||||
exit(1)
|
Loading…
Reference in New Issue
Block a user