2022-09-22 16:13:28 +03:00
|
|
|
from requests import get
|
|
|
|
from typing import List, Union
|
|
|
|
from xmltodict import parse as xmlparse
|
|
|
|
|
2022-09-23 14:53:56 +03:00
|
|
|
from pyrmv.utility.find_exception import find_exception
|
|
|
|
|
2022-09-22 16:13:28 +03:00
|
|
|
try:
|
|
|
|
from typing import Literal
|
|
|
|
except ImportError:
|
|
|
|
from typing_extensions import Literal
|
|
|
|
|
2022-09-23 12:49:11 +03:00
|
|
|
# 2.17. Reconstruction (recon)
|
|
|
|
def trip_recon(accessId: str,
|
2022-09-22 16:13:28 +03:00
|
|
|
json: bool = True
|
|
|
|
) -> dict:
|
|
|
|
|
|
|
|
if json:
|
|
|
|
headers = {"Accept": "application/json"}
|
|
|
|
else:
|
|
|
|
headers = {"Accept": "application/xml"}
|
|
|
|
|
|
|
|
payload = {}
|
|
|
|
|
|
|
|
for var, val in locals().items():
|
|
|
|
if str(var) not in ["json", "headers", "payload"]:
|
|
|
|
if val != None:
|
|
|
|
payload[str(var)] = val
|
|
|
|
|
2022-09-23 12:49:11 +03:00
|
|
|
output = get("https://www.rmv.de/hapi/recon", params=payload, headers=headers)
|
2022-09-22 16:13:28 +03:00
|
|
|
|
2022-09-23 14:53:56 +03:00
|
|
|
find_exception(output.json())
|
|
|
|
|
2022-09-22 16:13:28 +03:00
|
|
|
if json:
|
|
|
|
return output.json()
|
|
|
|
else:
|
|
|
|
return xmlparse(output.content)
|