Compare commits

..

2 Commits

Author SHA1 Message Date
Fred Boniface 452ce699ee Add source file to YAML output 2024-05-02 12:19:38 +01:00
Fred Boniface 259c5bc9b7 Attempt adding file name to output 2024-05-02 12:17:46 +01:00
4 changed files with 42 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"
@ -35,4 +38,26 @@ def load():
"envname": "DG_GITEA_SSHPORT",
"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,18 @@ 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' #source_file: {pis["diagram_file"]}\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'
manual_review += f' #source_file: {pis["diagram_file"]}\n'
for service in pis["services"]:
crs = []
if service and service['stops']:
@ -25,4 +31,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,14 +36,19 @@ 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': [],
'diagram_file': item['diagram_file']
}
for service in item['services']:
service_detail = owlboard_connector.get_service_detail(service['trainUid'], item['date'])
@ -65,4 +69,4 @@ def start():
if __name__ == "__main__":
start()
print("To use local mode, please call `main.py local`")