Kind of there, much tidying to do!

This commit is contained in:
Fred Boniface 2024-02-21 22:49:40 +00:00
parent 1b658209ad
commit d1728770c3
5 changed files with 64 additions and 28 deletions

View File

@ -0,0 +1 @@
,fred.boniface,bedroom.ws.fjla.net,21.02.2024 22:41,file:///home/fred.boniface/.config/libreoffice/4;

View File

@ -1,4 +1,5 @@
import owlboard_connector
import sys
def humanYaml(pis_list):
additional_pis = ''
@ -7,17 +8,25 @@ def humanYaml(pis_list):
if len(pis['services']) == 1:
print(f"Only one valid service for {pis['pis']}")
crs = []
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' stops: [{",".join(crs)}]\n'
print(pis)
try:
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' stops: [{",".join(crs)}]\n'
except Exception as err:
print(err)
elif len(pis['services']) > 1:
print(f"More than one possible service for {pis['pis']}")
manual_review += f' - code: "{pis["pis"]}"\n'
for service in pis["services"]:
crs = []
for stop in service['stops']:
crs.append(owlboard_connector.convert_tiploc_to_crs(stop))
manual_review += f'OR stops:[{",".join(crs)}]\n'
print(pis)
try:
manual_review += f' - code: "{pis["pis"]}"\n'
for service in pis["services"]:
crs = []
for stop in service['stops']:
crs.append(owlboard_connector.convert_tiploc_to_crs(stop))
manual_review += f'OR stops:[{",".join(crs)}]\n'
except Exception as err:
print(err)
return additional_pis + manual_review

View File

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

View File

@ -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
@ -59,5 +59,7 @@ def start():
if __name__ == "__main__":
start()

View File

@ -49,20 +49,27 @@ def get_services(headcode, date):
return results
def get_service_detail(trainUid, date):
print("Getting GWR service details: ", trainUid, ", ", date)
url = OB_TRN_BASE_URL + f"{date.isoformat()}/byTrainUid/{trainUid}"
print(url)
res = requests.get(url, headers=HEADERS)
if res.status_code == 200:
json_res = res.json()
if json_res:
svc_detail = {
'stops': json_res['stops'],
'existing_pis': json_res.get('pis', None),
'vstp': json_res.get('vstp', False)
}
return organise_svc(svc_detail)
try:
print("Getting GWR service details: ", trainUid, ", ", date)
url = OB_TRN_BASE_URL + f"{date.isoformat()}/byTrainUid/{trainUid}"
print(url)
res = requests.get(url, headers=HEADERS)
if res.status_code == 200:
json_res = res.json()
if json_res:
svc_detail = {
'stops': json_res['stops'],
'vstp': json_res.get('vstp', False)
}
organised = 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):
stop_tiplocs = []
@ -76,7 +83,7 @@ def organise_svc(input):
if 'pis' in input and input['pis'].get('skipCount', 0) == 0:
existingPis = True
return {'stops': stop_tiplocs, 'existingPis': existingPis, 'vstp': vstp}
return {'stops': stop_tiplocs, 'vstp': vstp}
def convert_tiploc_to_crs(tiploc):
res = requests.get(OB_TIP_BASE_URL + tiploc.upper(), headers=HEADERS)
@ -85,4 +92,4 @@ def convert_tiploc_to_crs(tiploc):
if json_res:
crs = json_res[0]['3ALPHA']
print(f"TIPLOC: {tiploc}, CRS: {crs}")
return crs
return crs.lower()