|
3 | 3 | from sqlalchemy_utils import database_exists, create_database
|
4 | 4 |
|
5 | 5 | # Determine if app is ran from docker or local by testing the env var "IS_LOCAL"
|
6 |
| -IS_LOCAL = os.getenv('IS_LOCAL') |
7 |
| -BASE_PATH = '../local_files/' if IS_LOCAL == 'True' else '/app/static/' |
| 6 | +IS_LOCAL = os.getenv("IS_LOCAL") |
| 7 | +BASE_PATH = "../local_files/" if IS_LOCAL == "True" else "/app/static/" |
8 | 8 |
|
9 | 9 | # Initiate postgres DB
|
10 | 10 | # best practices is to have only one engine per application process
|
11 | 11 | # https://docs.sqlalchemy.org/en/13/core/connections.html
|
12 |
| -POSTGRES_PASSWORD = os.getenv('POSTGRES_PASSWORD', 'thispasswordisverysecure') |
13 |
| -POSTGRES_DATABASE = os.getenv('POSTGRES_DATABASE', 'paws') |
14 |
| -POSTGRES_USER = os.getenv('POSTGRES_USER', 'postgres') |
15 |
| - |
16 |
| -if IS_LOCAL == 'True': |
17 |
| - DB = os.getenv('LOCAL_DB_IP', 'postgresql://postgres:' + POSTGRES_PASSWORD + '@localhost:5432/' + POSTGRES_DATABASE) |
| 12 | +POSTGRES_PASSWORD = os.getenv("POSTGRES_PASSWORD", "thispasswordisverysecure") |
| 13 | +POSTGRES_DATABASE = os.getenv("POSTGRES_DATABASE", "paws") |
| 14 | +POSTGRES_USER = os.getenv("POSTGRES_USER", "postgres") |
| 15 | + |
| 16 | +if IS_LOCAL == "True": |
| 17 | + DB = os.getenv( |
| 18 | + "LOCAL_DB_IP", |
| 19 | + "postgresql://postgres:" |
| 20 | + + POSTGRES_PASSWORD |
| 21 | + + "@localhost:5432/" |
| 22 | + + POSTGRES_DATABASE, |
| 23 | + ) |
18 | 24 | else:
|
19 |
| - DB = 'postgresql://' + POSTGRES_USER + ':' + POSTGRES_PASSWORD + '@paws-compose-db/' + POSTGRES_DATABASE |
| 25 | + DB = ( |
| 26 | + "postgresql://" |
| 27 | + + POSTGRES_USER |
| 28 | + + ":" |
| 29 | + + POSTGRES_PASSWORD |
| 30 | + + "@paws-compose-db/" |
| 31 | + + POSTGRES_DATABASE |
| 32 | + ) |
20 | 33 |
|
21 | 34 | engine = db.create_engine(DB)
|
22 | 35 |
|
23 | 36 | if not database_exists(engine.url):
|
24 | 37 | create_database(engine.url)
|
25 | 38 |
|
26 | 39 | # Initiate local file system
|
27 |
| -RAW_DATA_PATH = BASE_PATH + 'raw_data/' |
28 |
| -OUTPUT_PATH = BASE_PATH + 'output/' |
29 |
| -LOGS_PATH = BASE_PATH + 'logs/' |
30 |
| -CURRENT_SOURCE_FILES_PATH = RAW_DATA_PATH + 'current/' |
31 |
| -REPORT_PATH = OUTPUT_PATH + 'reports/' |
32 |
| -ZIPPED_FILES = BASE_PATH + 'zipped/' |
| 40 | +RAW_DATA_PATH = BASE_PATH + "raw_data/" |
| 41 | +OUTPUT_PATH = BASE_PATH + "output/" |
| 42 | +LOGS_PATH = BASE_PATH + "logs/" |
| 43 | +CURRENT_SOURCE_FILES_PATH = RAW_DATA_PATH + "current/" |
| 44 | +REPORT_PATH = OUTPUT_PATH + "reports/" |
| 45 | +ZIPPED_FILES = BASE_PATH + "zipped/" |
33 | 46 |
|
34 | 47 | os.makedirs(BASE_PATH, exist_ok=True)
|
35 | 48 | os.makedirs(RAW_DATA_PATH, exist_ok=True)
|
|
39 | 52 | os.makedirs(REPORT_PATH, exist_ok=True)
|
40 | 53 | os.makedirs(ZIPPED_FILES, exist_ok=True)
|
41 | 54 |
|
| 55 | +if not (os.path.exists(LOGS_PATH + "last_execution.json")): |
| 56 | + f = open(LOGS_PATH + "last_execution.json", "w") # Prevent 500 error from /api/statistics |
| 57 | + f.write("{}") |
| 58 | + f.close() |
0 commit comments