- zdroje rb, unicredit a air - nahore ve Swaggeru prehled nabizenych a nenabizenych bank s duvody - GET /status s prehledem vypadku stahovani u jednotlivych bank - prazdna promenna prostredi znamena vychozi hodnotu - popis stahovani v documentation/stahovani.md
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
"""Air Bank: the GraphQL endpoint used by the bank's own rate list page."""
|
|
|
|
import json
|
|
from datetime import date
|
|
|
|
from app.models import ParsedRates
|
|
from app.sources.base import make_rate
|
|
|
|
QUERY = "{ exchangeRates { rates { code buy sell quantity lastRevisionDate } } }"
|
|
ISO_DATE_LENGTH = 10
|
|
|
|
|
|
def parse(document: str) -> ParsedRates:
|
|
items = json.loads(document)["data"]["exchangeRates"]["rates"]
|
|
|
|
# The source has no validity date, only a revision date that some currencies leave empty.
|
|
# The list is valid since its latest revision, which can be the previous day.
|
|
revisions = [item["lastRevisionDate"] for item in items if item["lastRevisionDate"]]
|
|
if not revisions:
|
|
raise ValueError("Air Bank revision date not found")
|
|
|
|
rates = [
|
|
make_rate(
|
|
currency=item["code"],
|
|
amount=item["quantity"],
|
|
buy=item["buy"],
|
|
sell=item["sell"],
|
|
)
|
|
for item in items
|
|
if item["buy"] and item["sell"]
|
|
]
|
|
return ParsedRates(valid_date=date.fromisoformat(max(revisions)[:ISO_DATE_LENGTH]), rates=rates)
|