Skip to content

Commit

Permalink
David/20240124 test env a (#38)
Browse files Browse the repository at this point in the history
clean up load_dotenv override any already loaded vars with new ones and fix order of loading env variables - 2h
  • Loading branch information
dmossakowski committed Jan 24, 2024
1 parent 6c91e25 commit 8e11805
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 27 deletions.
5 changes: 0 additions & 5 deletions competitionsEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@

from functools import lru_cache, reduce
import logging
from dotenv import load_dotenv



load_dotenv()

DATA_DIRECTORY = os.getenv('DATA_DIRECTORY')

Expand Down
3 changes: 0 additions & 3 deletions main_app_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
stream_with_context, copy_current_request_context, make_response

import logging
from dotenv import load_dotenv

from flask import Blueprint
import activities_db as activity_engine
Expand Down Expand Up @@ -62,8 +61,6 @@

languages = {}

load_dotenv()

DATA_DIRECTORY = os.getenv('DATA_DIRECTORY')

if DATA_DIRECTORY is None:
Expand Down
36 changes: 26 additions & 10 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,29 @@
import base64
import io
import urllib
import os
import traceback
import time
import datetime
import threading
import random

from functools import wraps

#import fastapi_test
from dotenv import load_dotenv
load_dotenv(override=True)

DATA_DIRECTORY = os.getenv('DATA_DIRECTORY')

print("server DATA_DIRECTORY="+str(DATA_DIRECTORY))

if DATA_DIRECTORY is None:
DATA_DIRECTORY = os.getcwd()
elif not os.path.exists(DATA_DIRECTORY):
print("DATA_DIRECTORY does not exist. Creating it"+str(DATA_DIRECTORY))
os.makedirs(DATA_DIRECTORY)

from flask import Flask, redirect, url_for, session, request, render_template, send_file, jsonify, Response, \
stream_with_context, copy_current_request_context

Expand All @@ -31,13 +50,9 @@
import requests
import json

import os
import traceback
import time
import datetime
import threading
import random
import logging


from main_app_ui import app_ui, languages
from skala_api import skala_api_app
import competitionsEngine
Expand All @@ -57,9 +72,6 @@

#from flask_openapi3 import OpenAPI, Info, Tag



load_dotenv()
# https://docs.authlib.org/en/latest/flask/2/index.html#flask-oauth2-server
# If you are developing on your localhost, remember to set the environment variable:
# export AUTHLIB_INSECURE_TRANSPORT=true
Expand All @@ -68,9 +80,12 @@

DATA_DIRECTORY = os.getenv('DATA_DIRECTORY')

print("server DATA_DIRECTORY="+str(DATA_DIRECTORY))

if DATA_DIRECTORY is None:
DATA_DIRECTORY = os.getcwd()



# Configuration
GOOGLE_CLIENT_ID = os.getenv("GOOGLE_CLIENT_ID", None)
GOOGLE_CLIENT_SECRET = os.getenv("GOOGLE_CLIENT_SECRET", None)
Expand Down Expand Up @@ -184,6 +199,7 @@ def init_logging(log_file=None, append=False, console_loglevel=logging.INFO):
filemode_val = 'a'
else:
filemode_val = 'w'

logging.basicConfig(level=logging.DEBUG,
format="%(asctime)s %(levelname)s %(threadName)s %(name)s %(message)s",
# datefmt='%m-%d %H:%M',
Expand Down
3 changes: 0 additions & 3 deletions skala_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
stream_with_context, copy_current_request_context, g

import logging
from dotenv import load_dotenv

from flask import Blueprint
import activities_db as activities_db
Expand Down Expand Up @@ -72,8 +71,6 @@

languages = {}

load_dotenv()

grades = ['1', '2', '3', '4a', '4b', '4c', '5a','5a+', '5b', '5c','5c+', '6a', '6a+', '6b', '6b+', '6c', '6c+', '7a', '7a+', '7b', '7b+', '7c', '7c+', '8a', '8a+', '8b', '8b+', '8c', '8c+', '9a', '9a+', '9b', '9b+', '9c']


Expand Down
25 changes: 19 additions & 6 deletions skala_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from collections import Counter
import tracemalloc
import sqlite3 as lite
import uuid
import copy
from threading import RLock
import csv

import requests

Expand All @@ -38,12 +35,27 @@
stream_with_context, copy_current_request_context

import logging
from dotenv import load_dotenv

DATA_DIRECTORY = os.getenv('DATA_DIRECTORY')

print("DATA_DIRECTORY="+str(DATA_DIRECTORY))

SPOTIFY_APP_ID = os.getenv('SPOTIFY_APP_ID')

print("SPOTIFY_APP_ID="+str(SPOTIFY_APP_ID))


ENV_VAR = os.getenv('ENV_VAR')

print("ENV_VAR="+str(ENV_VAR))


LINKED_VAR = os.getenv('LINKED_VAR')

print("LINKED_VAR="+str(LINKED_VAR))


load_dotenv()

DATA_DIRECTORY = os.getenv('DATA_DIRECTORY')

if DATA_DIRECTORY is None:
DATA_DIRECTORY = os.getcwd()
Expand All @@ -64,6 +76,7 @@
def init():
logging.info('initializing skala_db...')


if not os.path.exists(DATA_DIRECTORY):
os.makedirs(DATA_DIRECTORY)

Expand Down

0 comments on commit 8e11805

Please sign in to comment.