diff --git a/.gitignore b/.gitignore index c3559a6..c874351 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ env_conf include *.docx git +run.sh # ---> Python # Byte-compiled / optimized / DLL files diff --git a/src/config.py b/src/config.py index f6679f8..3f2803f 100644 --- a/src/config.py +++ b/src/config.py @@ -1,7 +1,10 @@ # Load configuration from file/env variables +import os + def load(): - toLoad = [ + cfg = {} + toLoad = [ { "envname": "DG_IMAP_HOST", "filepath": "/owlboard/dgp/imap/host" @@ -35,4 +38,26 @@ def load(): "envname": "DG_GITEA_SSHPORT", "filepath": "/owlboard/dgp/gitea/sshport" } - ] \ No newline at end of file + ] + + for item in toLoad: + filepath = item["filepath"] + envname = item["envname"] + default = item.get("default") + + # Try to load value from file + try: + with open(filepath, "r") as file: + value = file.read().strip() + except FileNotFoundError: + # If file doesn't exist, try to get value from environment variable + value = os.environ.get(envname) + + # If value is still not found, use the default if provided + if value is None and default is not None: + value = default + + # Add the value to the cfg dictionary + cfg[envname] = value + + return cfg diff --git a/src/formatter.py b/src/formatter.py index 84ade0b..6c5972a 100644 --- a/src/formatter.py +++ b/src/formatter.py @@ -12,12 +12,16 @@ def humanYaml(pis_list): for stop in pis['services'][0]['stops']: crs.append(owlboard_connector.convert_tiploc_to_crs(stop)) additional_pis += f' - code: "{pis["pis"]}"\n' + additional_pis += f' #headcode: {pis["headcode"]}\n' + additional_pis += f' #date: {pis["date"]}\n' additional_pis += f' stops: [{",".join(crs)}]\n' except Exception as err: print(err) elif len(pis['services']) > 1: manual_review += f'## THIS CODE REQUIRES MANUAL VERIFICATION\n' manual_review += f' - code: "{pis["pis"]}"\n' + manual_review += f' #headcode: {pis["headcode"]}\n' + manual_review += f' #date: {pis["date"]}\n' for service in pis["services"]: crs = [] if service and service['stops']: @@ -25,4 +29,4 @@ def humanYaml(pis_list): crs.append(owlboard_connector.convert_tiploc_to_crs(stop)) manual_review += f' stops: [{",".join(crs)}]\n' - return additional_pis + manual_review + return "FOR REVIEW\n" + additional_pis + manual_review diff --git a/src/local_mode.py b/src/local_mode.py index 43668a1..117c898 100644 --- a/src/local_mode.py +++ b/src/local_mode.py @@ -1,5 +1,4 @@ import parse_docx, pis_find, owlboard_connector, formatter, gitea_connector - import os, sys def start(): @@ -37,13 +36,17 @@ def start(): get_detail.append({ 'pis': code['pis'], 'services': services, - 'date': code['date'] + 'diagram_file': code['file'], + 'date': code['date'], + 'headcode': code['headcode'], }) details = [] for item in get_detail: detail = { 'pis': item['pis'], + 'headcode': item['headcode'], + 'date': item['date'], 'services': [], } for service in item['services']: @@ -65,4 +68,4 @@ def start(): if __name__ == "__main__": - start() \ No newline at end of file + print("To use local mode, please call `main.py local`") \ No newline at end of file