rewe-vereinscheine-fetcher/verein_fetcher.py

26 lines
920 B
Python
Raw Permalink Normal View History

2023-05-15 09:30:56 +02:00
import requests
from verein import Verein
def get_verein_ids_near_location(latitude: float, longitude: float, count: int = 10):
response = requests.get(
f"https://scheinefuervereine.rewe.de/consumer-api/customer.php?action=get_clubs_near_location&count={count}&lat={latitude}&long={longitude}")
if not response.ok:
return []
data = response.json()['data']
return [verein['partyID'] for verein in data]
def get_verein_for_id(verein_id: int) -> Verein:
response = requests.get(
f"https://scheinefuervereine.rewe.de/consumer-api/customer.php?action=get_club&id={verein_id}")
if not response.ok:
raise RuntimeError
data = response.json()['data']
2023-05-15 10:32:52 +02:00
address = data['address']
return Verein(data['accountName'], address['address'], address['city'], address['postCode'], data['totalBalance'],
data['availableBalance'], data['redeemed'])