Even more meating
This commit is contained in:
parent
d5d7b6626b
commit
4d3f7ce342
@ -29,7 +29,11 @@ def start():
|
|||||||
print("No DOCX files found")
|
print("No DOCX files found")
|
||||||
|
|
||||||
print(f"Found {len(results)} PIS Codes in documents")
|
print(f"Found {len(results)} PIS Codes in documents")
|
||||||
pis_find.run(results)
|
missing_pis = pis_find.run(results)
|
||||||
|
for code in missing_pis:
|
||||||
|
services = owlboard_connector.get_services(code['headcode'], code['date'])
|
||||||
|
print(services)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -7,8 +7,11 @@
|
|||||||
|
|
||||||
import requests, os
|
import requests, os
|
||||||
|
|
||||||
OB_BASE_URL = "https://owlboard.info/api/v2/pis/byCode/"
|
#OB_PIS_BASE_URL = "https://owlboard.info/api/v2/pis/byCode/"
|
||||||
OB_TEST_URL = OB_BASE_URL + "5001"
|
#OB_TRN_BASE_URL = "https://owlboard.info/api/v2/timetable/train/"
|
||||||
|
OB_PIS_BASE_URL = "http://localhost:8460/api/v2/pis/byCode/"
|
||||||
|
OB_TRN_BASE_URL = "http://localhost:8460/api/v2/timetable/train/"
|
||||||
|
OB_TEST_URL = OB_PIS_BASE_URL + "5001"
|
||||||
UUID = os.environ.get('DGP_OB_UUID')
|
UUID = os.environ.get('DGP_OB_UUID')
|
||||||
HEADERS = {
|
HEADERS = {
|
||||||
'user-agent': 'owlboard-diagram-parser',
|
'user-agent': 'owlboard-diagram-parser',
|
||||||
@ -31,7 +34,7 @@ def check_connection():
|
|||||||
|
|
||||||
def find_pis_code(code):
|
def find_pis_code(code):
|
||||||
print("Searching for PIS Code: ", code)
|
print("Searching for PIS Code: ", code)
|
||||||
url = OB_BASE_URL + code
|
url = OB_PIS_BASE_URL + code
|
||||||
res = requests.get(url, headers=HEADERS)
|
res = requests.get(url, headers=HEADERS)
|
||||||
if res.status_code == 200:
|
if res.status_code == 200:
|
||||||
json_response = res.json()
|
json_response = res.json()
|
||||||
@ -42,3 +45,46 @@ def find_pis_code(code):
|
|||||||
else:
|
else:
|
||||||
print("Unable to reach OwlBoard. STATUS: ", res.status_code)
|
print("Unable to reach OwlBoard. STATUS: ", res.status_code)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def get_services(headcode, date):
|
||||||
|
print("Finding GWR service: ", headcode, ", ", date)
|
||||||
|
results = []
|
||||||
|
url = OB_TRN_BASE_URL + f"now/headcode/{headcode.lower()}"
|
||||||
|
print(url)
|
||||||
|
res = requests.get(url, headers=HEADERS)
|
||||||
|
if res.status_code == 200:
|
||||||
|
json_res = res.json()
|
||||||
|
for item in json_res:
|
||||||
|
if item['operator'] == 'GW':
|
||||||
|
results.append(item)
|
||||||
|
print(f"Found {len(results)} valid GWR Service")
|
||||||
|
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 and isinstance(dict, json_res):
|
||||||
|
svc_detail = {
|
||||||
|
'stops': json_res['stops'],
|
||||||
|
'existing_pis': json_res['pis'],
|
||||||
|
'vstp': json_res['vstp']
|
||||||
|
}
|
||||||
|
|
||||||
|
return organise_svc(svc_detail)
|
||||||
|
|
||||||
|
def organise_svc(input):
|
||||||
|
stop_tiplocs = []
|
||||||
|
vstp = input['vstp']
|
||||||
|
|
||||||
|
for stop in input['stops']:
|
||||||
|
if stop['isPublic']:
|
||||||
|
stop_tiplocs.append(stop['tiploc'])
|
||||||
|
|
||||||
|
if input['pis']['skipCount'] == 0:
|
||||||
|
existingPis = True
|
||||||
|
|
||||||
|
return {'stops': stop_tiplocs, 'vstp': vstp, 'existingPis': existingPis}
|
@ -1,5 +1,6 @@
|
|||||||
### This uses the 'python-docx-2023' module
|
### This uses the 'python-docx-2023' module
|
||||||
from docx import Document
|
from docx import Document
|
||||||
|
from datetime import datetime
|
||||||
import re
|
import re
|
||||||
|
|
||||||
### This can parse each table. What needs to happen next
|
### This can parse each table. What needs to happen next
|
||||||
@ -37,6 +38,7 @@ def extract_tables(file_path):
|
|||||||
pis_and_headcode = match_pis_and_headcode(data)
|
pis_and_headcode = match_pis_and_headcode(data)
|
||||||
if pis_and_headcode:
|
if pis_and_headcode:
|
||||||
pis_and_headcode['source_file'] = file_path
|
pis_and_headcode['source_file'] = file_path
|
||||||
|
pis_and_headcode['date'] = datetime.strptime(file_path.split('_')[0], "%Y%m%d")
|
||||||
pis_info.append(pis_and_headcode)
|
pis_info.append(pis_and_headcode)
|
||||||
|
|
||||||
return(pis_info)
|
return(pis_info)
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import owlboard_connector
|
import owlboard_connector
|
||||||
import requests
|
import requests, sys
|
||||||
|
|
||||||
def run(data_list):
|
def run(data_list):
|
||||||
deduplicated_data = dedup(data_list)
|
deduplicated_data = dedup(data_list)
|
||||||
print(f"Removed {len(data_list) - len(deduplicated_data)} duplicate codes")
|
print(f"Removed {len(data_list) - len(deduplicated_data)} duplicate codes")
|
||||||
print(f"Searching for {len(deduplicated_data)} PIS codes")
|
print(f"Searching for {len(deduplicated_data)} PIS codes")
|
||||||
missing_data = find_missing(deduplicated_data)
|
missing_data = find_missing(deduplicated_data)
|
||||||
print(f"{missing_data} missing PIS codes in OwlBoard data")
|
print(f"{len(missing_data)} missing PIS codes in OwlBoard data")
|
||||||
|
return missing_data
|
||||||
|
|
||||||
def dedup(data_list):
|
def dedup(data_list):
|
||||||
unique_dicts = {d['pis']: d for d in data_list}.values()
|
unique_dicts = {d['pis']: d for d in data_list}.values()
|
||||||
@ -17,8 +17,8 @@ def dedup(data_list):
|
|||||||
|
|
||||||
## AUTH REQUIRED!!! Move to owlboard_connector.py
|
## AUTH REQUIRED!!! Move to owlboard_connector.py
|
||||||
def find_missing(data_list):
|
def find_missing(data_list):
|
||||||
#BASEURL = 'http://localhost:8460/api/v2/pis/byCode/'
|
BASEURL = 'http://localhost:8460/api/v2/pis/byCode/'
|
||||||
BASEURL = 'https://owlboard.info/api/v2/pis/byCode/'
|
#BASEURL = 'https://owlboard.info/api/v2/pis/byCode/'
|
||||||
missing_data = []
|
missing_data = []
|
||||||
|
|
||||||
for item in data_list:
|
for item in data_list:
|
||||||
@ -27,5 +27,5 @@ def find_missing(data_list):
|
|||||||
pis_code_res = owlboard_connector.find_pis_code(pis_code)
|
pis_code_res = owlboard_connector.find_pis_code(pis_code)
|
||||||
if not pis_code_res:
|
if not pis_code_res:
|
||||||
print("PIS Code ", pis_code, " not found in existing data")
|
print("PIS Code ", pis_code, " not found in existing data")
|
||||||
missing_data.append(pis_code)
|
missing_data.append(item)
|
||||||
print(missing_data)
|
return missing_data
|
Reference in New Issue
Block a user