From 23aff0ddf087ec17b2c1bcafd98261d3d48b3044 Mon Sep 17 00:00:00 2001 From: Remy Moll Date: Sat, 30 Oct 2021 15:14:13 +0200 Subject: [PATCH] basic sbb api --- apis/__init__.py | 0 apis/sbb.py | 41 +++++++++++++++++++++++++++++++++++++ apis/weather.py | 0 event_providers/__init__.py | 0 event_providers/hikes.py | 0 5 files changed, 41 insertions(+) create mode 100644 apis/__init__.py create mode 100644 apis/sbb.py create mode 100644 apis/weather.py create mode 100644 event_providers/__init__.py create mode 100644 event_providers/hikes.py diff --git a/apis/__init__.py b/apis/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apis/sbb.py b/apis/sbb.py new file mode 100644 index 0000000..a1048a6 --- /dev/null +++ b/apis/sbb.py @@ -0,0 +1,41 @@ +import tortilla +import requests + + +def get_auth(): + token_query = { + 'grant_type': 'client_credentials', + 'client_id': 'af929f08', + 'client_secret': 'ae61e214f679558c28678d5c638c5725' + } + + response = requests.post('https://sso-int.sbb.ch/auth/realms/SBB_Public/protocol/openid-connect/token', data=token_query).json() + + token = response["access_token"] + auth = { + 'Authorization': f"Bearer {token}", + 'X-Contract-Id': 'PLY223P', + # 'X-Conversation-Id': str(conv_id), + } + return auth + + + +SBB = tortilla.wrap('https://b2p-int.api.sbb.ch/api') +SBB.config.headers = get_auth() +# SBB.config.headers = { +# "grant_type" : "client_credentials", +# "client_secret" : "ae61e214f679558c28678d5c638c5725", +# "client_id" : "af929f08pied!", +# } + + +# Authorization: Bearer $accessToken' \ +# ​-H 'Cache-Control: no-cache' \ +# ​-H 'Accept: application/json' \ +# ​-H 'X-Contract-Id: ABC1234' \ +# ​-H 'X-Conversation-Id: e5eeb775-1e0e-4f89-923d-afa780ef844b + + +loc = SBB.locations +print(loc.get(params = {"name":"Bern"})) \ No newline at end of file diff --git a/apis/weather.py b/apis/weather.py new file mode 100644 index 0000000..e69de29 diff --git a/event_providers/__init__.py b/event_providers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/event_providers/hikes.py b/event_providers/hikes.py new file mode 100644 index 0000000..e69de29