Initial version
This commit is contained in:
commit
b49750de94
7 changed files with 99 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
__pycache__
|
||||
venv
|
||||
*.egg-info
|
4
README.md
Normal file
4
README.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
# WiFi SNCF API
|
||||
|
||||
This package provides an asyncio-enabled, pythonic wrapper around the
|
||||
"SNCF_WIFI_INOUI" API.
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
aiohttp
|
||||
aiodns
|
25
setup.py
Normal file
25
setup.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
|
||||
def parse_requirements():
|
||||
reqs = []
|
||||
with open("requirements.txt", "r") as handle:
|
||||
for line in handle:
|
||||
reqs.append(line)
|
||||
return reqs
|
||||
|
||||
|
||||
setup(
|
||||
name="wifi_sncf_api",
|
||||
version="0.1",
|
||||
description="API de wifi.sncf",
|
||||
author="tobast",
|
||||
author_email="contact@tobast.fr",
|
||||
license="LICENSE",
|
||||
packages=find_packages(),
|
||||
include_package_data=True,
|
||||
long_description=open("README.md").read(),
|
||||
install_requires=parse_requirements(),
|
||||
)
|
20
test.py
Normal file
20
test.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
import asyncio
|
||||
import logging
|
||||
import train_api
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def mainloop():
|
||||
async with train_api.ApiSession() as api:
|
||||
details = await api.details()
|
||||
logger.info("Details: <%s>", details)
|
||||
|
||||
|
||||
def main():
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
asyncio.get_event_loop().run_until_complete(mainloop())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
0
wifi_sncf/__init__.py
Normal file
0
wifi_sncf/__init__.py
Normal file
45
wifi_sncf/train_api.py
Normal file
45
wifi_sncf/train_api.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
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")
|
Loading…
Add table
Reference in a new issue