46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
import asyncio
|
|
import aiohttp
|
|
import json
|
|
|
|
|
|
class ApiSession:
|
|
ENDPOINT = "https://wifi.sncf/router/api"
|
|
|
|
def __init__(self):
|
|
self.session = aiohttp.ClientSession()
|
|
|
|
async def __aenter__(self):
|
|
return self
|
|
|
|
async def __aexit__(self, *args):
|
|
await self.session.close()
|
|
|
|
async def _json_api_request(self, endpoint):
|
|
url = self.ENDPOINT + endpoint
|
|
async with self.session.get(url) as response:
|
|
return await response.json()
|
|
|
|
def details(self):
|
|
return self._json_api_request("/train/details")
|
|
|
|
def gps(self):
|
|
return self._json_api_request("/train/gps")
|
|
|
|
def graph(self):
|
|
return self._json_api_request("/train/graph")
|
|
|
|
def coverage(self):
|
|
return self._json_api_request("/train/coverage")
|
|
|
|
def connection_status(self):
|
|
return self._json_api_request("/connection/status")
|
|
|
|
def connection_statistics(self):
|
|
return self._json_api_request("/connection/statistics")
|
|
|
|
def modules(self):
|
|
return self._json_api_request("/configuration/modules")
|
|
|
|
def bar(self):
|
|
return self._json_api_request("/bar/attendance")
|