Output formatting

This commit is contained in:
Fred Boniface 2024-02-21 20:22:58 +00:00
parent b4fb7211f3
commit 3faed4a41c
6 changed files with 46 additions and 1294 deletions

File diff suppressed because one or more lines are too long

24
src/formatter.py Normal file
View File

@ -0,0 +1,24 @@
import owlboard_connector
def humanYaml(pis_list):
additional_pis = ''
manual_review = ''
for pis in 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'
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(additional_pis)
print(manual_review)

View File

@ -1,4 +1,4 @@
import parse_docx, pis_find, owlboard_connector import parse_docx, pis_find, owlboard_connector, formatter
import os, sys import os, sys
@ -52,7 +52,8 @@ def start():
details.append(detail) details.append(detail)
print(details) formatted_additions = formatter.humanYaml(details)
print(formatted_additions)

View File

@ -9,8 +9,10 @@ import requests, os
#OB_PIS_BASE_URL = "https://owlboard.info/api/v2/pis/byCode/" #OB_PIS_BASE_URL = "https://owlboard.info/api/v2/pis/byCode/"
#OB_TRN_BASE_URL = "https://owlboard.info/api/v2/timetable/train/" #OB_TRN_BASE_URL = "https://owlboard.info/api/v2/timetable/train/"
#OB_TIP_BASE_URL = "https://owlboard.info/api/v2/ref/locationCode/tiploc/"
OB_PIS_BASE_URL = "http://localhost:8460/api/v2/pis/byCode/" OB_PIS_BASE_URL = "http://localhost:8460/api/v2/pis/byCode/"
OB_TRN_BASE_URL = "http://localhost:8460/api/v2/timetable/train/" OB_TRN_BASE_URL = "http://localhost:8460/api/v2/timetable/train/"
OB_TIP_BASE_URL = "http://localhost:8460/api/v2/ref/locationCode/tiploc/"
OB_TEST_URL = OB_PIS_BASE_URL + "5001" OB_TEST_URL = OB_PIS_BASE_URL + "5001"
UUID = os.environ.get('DGP_OB_UUID') UUID = os.environ.get('DGP_OB_UUID')
HEADERS = { HEADERS = {
@ -74,4 +76,13 @@ 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, 'existingPis': existingPis, 'vstp': vstp}
def convert_tiploc_to_crs(tiploc):
res = requests.get(OB_TIP_BASE_URL + tiploc.upper(), headers=HEADERS)
if res.status_code == 200:
json_res = res.json()
if json_res:
crs = json_res[0]['3ALPHA']
print(f"TIPLOC: {tiploc}, CRS: {crs}")
return crs

View File

@ -1,6 +1,7 @@
import os, requests, yaml ## This module downloads and compiles a list of all PIS codes across all branches of the OwlBoard/Data repo.
## The function load_existing_pis() is expected to be used outside of the module.
API_KEY = os.environ.get('DGP_GITEA_KEY') import os, requests, yaml
## TESTING ## TESTING
GIT_URL = 'https://git.fjla.uk' GIT_URL = 'https://git.fjla.uk'

View File

@ -1,5 +1,7 @@
## This modile compares discovered PIS codes with existing PIS codes obtained by calling pis_fetch
import pis_fetch import pis_fetch
import requests, sys import sys
def run(data_list): def run(data_list):
deduplicated_data = dedup(data_list) deduplicated_data = dedup(data_list)
@ -24,11 +26,10 @@ def find_missing(data_list):
if pis_code: if pis_code:
code_exists = False code_exists = False
for existing_pis in existing_pis_list: for existing_pis in existing_pis_list:
if existing_pis['code'] == pis_code: if str(existing_pis['code']) == pis_code:
code_exists = True code_exists = True
break break
if not code_exists: if not code_exists:
print("PIS Code", pis_code, "not found in existing data")
missing_data.append(item) missing_data.append(item)
return missing_data return missing_data