Kind of there, much tidying to do!
This commit is contained in:
parent
1b658209ad
commit
d1728770c3
1
src/.~lock.20240221_file.docx#
Normal file
1
src/.~lock.20240221_file.docx#
Normal file
@ -0,0 +1 @@
|
|||||||
|
,fred.boniface,bedroom.ws.fjla.net,21.02.2024 22:41,file:///home/fred.boniface/.config/libreoffice/4;
|
@ -1,4 +1,5 @@
|
|||||||
import owlboard_connector
|
import owlboard_connector
|
||||||
|
import sys
|
||||||
|
|
||||||
def humanYaml(pis_list):
|
def humanYaml(pis_list):
|
||||||
additional_pis = ''
|
additional_pis = ''
|
||||||
@ -7,17 +8,25 @@ def humanYaml(pis_list):
|
|||||||
if len(pis['services']) == 1:
|
if len(pis['services']) == 1:
|
||||||
print(f"Only one valid service for {pis['pis']}")
|
print(f"Only one valid service for {pis['pis']}")
|
||||||
crs = []
|
crs = []
|
||||||
|
print(pis)
|
||||||
|
try:
|
||||||
for stop in pis['services'][0]['stops']:
|
for stop in pis['services'][0]['stops']:
|
||||||
crs.append(owlboard_connector.convert_tiploc_to_crs(stop))
|
crs.append(owlboard_connector.convert_tiploc_to_crs(stop))
|
||||||
additional_pis += f' - code: "{pis["pis"]}"\n'
|
additional_pis += f' - code: "{pis["pis"]}"\n'
|
||||||
additional_pis += f' stops: [{",".join(crs)}]\n'
|
additional_pis += f' stops: [{",".join(crs)}]\n'
|
||||||
|
except Exception as err:
|
||||||
|
print(err)
|
||||||
elif len(pis['services']) > 1:
|
elif len(pis['services']) > 1:
|
||||||
print(f"More than one possible service for {pis['pis']}")
|
print(f"More than one possible service for {pis['pis']}")
|
||||||
|
print(pis)
|
||||||
|
try:
|
||||||
manual_review += f' - code: "{pis["pis"]}"\n'
|
manual_review += f' - code: "{pis["pis"]}"\n'
|
||||||
for service in pis["services"]:
|
for service in pis["services"]:
|
||||||
crs = []
|
crs = []
|
||||||
for stop in service['stops']:
|
for stop in service['stops']:
|
||||||
crs.append(owlboard_connector.convert_tiploc_to_crs(stop))
|
crs.append(owlboard_connector.convert_tiploc_to_crs(stop))
|
||||||
manual_review += f'OR stops:[{",".join(crs)}]\n'
|
manual_review += f'OR stops:[{",".join(crs)}]\n'
|
||||||
|
except Exception as err:
|
||||||
|
print(err)
|
||||||
|
|
||||||
return additional_pis + manual_review
|
return additional_pis + manual_review
|
@ -1,2 +1,19 @@
|
|||||||
import requests
|
import requests, os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
BASE_URL = "https://git.fjla.uk/"
|
||||||
|
USER = 'owlbot'
|
||||||
|
TOKEN = os.environ.get('DGP_GITEA_TOK')
|
||||||
|
HEADERS = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'accept': 'application/json',
|
||||||
|
}
|
||||||
|
|
||||||
|
'''
|
||||||
|
I need a way here to get the original file from the 'main' branch and
|
||||||
|
append the generated PIS codes. Then push to a new generated branch.
|
||||||
|
|
||||||
|
Then a pull request should be created but can probably be done with actions.
|
||||||
|
In reality this program should just take in DOCX files and spit out formatted
|
||||||
|
PIS data to the repo, everything else can be handled at the repo level??
|
||||||
|
'''
|
@ -1,4 +1,4 @@
|
|||||||
import parse_docx, pis_find, owlboard_connector, formatter
|
import parse_docx, pis_find, owlboard_connector, formatter, gitea_connector
|
||||||
|
|
||||||
import os, sys
|
import os, sys
|
||||||
|
|
||||||
@ -59,5 +59,7 @@ def start():
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
start()
|
start()
|
@ -49,6 +49,7 @@ def get_services(headcode, date):
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
def get_service_detail(trainUid, date):
|
def get_service_detail(trainUid, date):
|
||||||
|
try:
|
||||||
print("Getting GWR service details: ", trainUid, ", ", date)
|
print("Getting GWR service details: ", trainUid, ", ", date)
|
||||||
url = OB_TRN_BASE_URL + f"{date.isoformat()}/byTrainUid/{trainUid}"
|
url = OB_TRN_BASE_URL + f"{date.isoformat()}/byTrainUid/{trainUid}"
|
||||||
print(url)
|
print(url)
|
||||||
@ -58,11 +59,17 @@ def get_service_detail(trainUid, date):
|
|||||||
if json_res:
|
if json_res:
|
||||||
svc_detail = {
|
svc_detail = {
|
||||||
'stops': json_res['stops'],
|
'stops': json_res['stops'],
|
||||||
'existing_pis': json_res.get('pis', None),
|
|
||||||
'vstp': json_res.get('vstp', False)
|
'vstp': json_res.get('vstp', False)
|
||||||
}
|
}
|
||||||
|
organised = organise_svc(svc_detail)
|
||||||
return organise_svc(svc_detail)
|
print(organised)
|
||||||
|
return organised
|
||||||
|
else:
|
||||||
|
print("Service Not Found")
|
||||||
|
sys.exit()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
def organise_svc(input):
|
def organise_svc(input):
|
||||||
stop_tiplocs = []
|
stop_tiplocs = []
|
||||||
@ -76,7 +83,7 @@ def organise_svc(input):
|
|||||||
if 'pis' in input and input['pis'].get('skipCount', 0) == 0:
|
if 'pis' in input and input['pis'].get('skipCount', 0) == 0:
|
||||||
existingPis = True
|
existingPis = True
|
||||||
|
|
||||||
return {'stops': stop_tiplocs, 'existingPis': existingPis, 'vstp': vstp}
|
return {'stops': stop_tiplocs, 'vstp': vstp}
|
||||||
|
|
||||||
def convert_tiploc_to_crs(tiploc):
|
def convert_tiploc_to_crs(tiploc):
|
||||||
res = requests.get(OB_TIP_BASE_URL + tiploc.upper(), headers=HEADERS)
|
res = requests.get(OB_TIP_BASE_URL + tiploc.upper(), headers=HEADERS)
|
||||||
@ -85,4 +92,4 @@ def convert_tiploc_to_crs(tiploc):
|
|||||||
if json_res:
|
if json_res:
|
||||||
crs = json_res[0]['3ALPHA']
|
crs = json_res[0]['3ALPHA']
|
||||||
print(f"TIPLOC: {tiploc}, CRS: {crs}")
|
print(f"TIPLOC: {tiploc}, CRS: {crs}")
|
||||||
return crs
|
return crs.lower()
|
||||||
|
Reference in New Issue
Block a user