Attempt adding file name to output

This commit is contained in:
Fred Boniface 2024-05-02 12:17:46 +01:00
parent bcac814800
commit 259c5bc9b7
4 changed files with 39 additions and 6 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@ env_conf
include
*.docx
git
run.sh
# ---> Python
# Byte-compiled / optimized / DLL files

View File

@ -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"
@ -36,3 +39,25 @@ def load():
"filepath": "/owlboard/dgp/gitea/sshport"
}
]
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

View File

@ -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

View File

@ -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()
print("To use local mode, please call `main.py local`")