Better naming for api wrappers
This commit is contained in:
parent
23aff0ddf0
commit
fe015d75e7
49
apis/sbb.py
49
apis/sbb.py
@ -2,40 +2,27 @@ import tortilla
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
def get_auth():
|
class SBBWrapper:
|
||||||
token_query = {
|
def __init__(self) -> None:
|
||||||
'grant_type': 'client_credentials',
|
self.wrapper = tortilla.wrap('https://b2p-int.api.sbb.ch/api')
|
||||||
'client_id': 'af929f08',
|
self.wrapper.config.headers = self.get_auth()
|
||||||
'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')
|
def get_auth(self):
|
||||||
SBB.config.headers = get_auth()
|
token_query = {
|
||||||
# SBB.config.headers = {
|
'grant_type': 'client_credentials',
|
||||||
# "grant_type" : "client_credentials",
|
'client_id': 'af929f08',
|
||||||
# "client_secret" : "ae61e214f679558c28678d5c638c5725",
|
'client_secret': 'ae61e214f679558c28678d5c638c5725'
|
||||||
# "client_id" : "af929f08pied!",
|
}
|
||||||
# }
|
|
||||||
|
|
||||||
|
response = requests.post('https://sso-int.sbb.ch/auth/realms/SBB_Public/protocol/openid-connect/token', data=token_query).json()
|
||||||
|
|
||||||
# Authorization: Bearer $accessToken' \
|
token = response["access_token"]
|
||||||
# -H 'Cache-Control: no-cache' \
|
auth = {
|
||||||
# -H 'Accept: application/json' \
|
'Authorization': f"Bearer {token}",
|
||||||
# -H 'X-Contract-Id: ABC1234' \
|
'X-Contract-Id': 'PLY223P',
|
||||||
# -H 'X-Conversation-Id: e5eeb775-1e0e-4f89-923d-afa780ef844b
|
# 'X-Conversation-Id': str(conv_id),
|
||||||
|
}
|
||||||
|
return auth
|
||||||
|
|
||||||
|
|
||||||
loc = SBB.locations
|
|
||||||
print(loc.get(params = {"name":"Bern"}))
|
|
0
models/__init__.py
Normal file
0
models/__init__.py
Normal file
19
models/events.py
Normal file
19
models/events.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
|
||||||
|
class User:
|
||||||
|
name = ""
|
||||||
|
event_preferences = []
|
||||||
|
event_blacklist = []
|
||||||
|
home_coordinates = []
|
||||||
|
group_size = 0
|
||||||
|
min_age = 0
|
||||||
|
max_age = 0
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
self.name = kwargs.pop("name")
|
||||||
|
self.home_coordinates = kwargs.pop("home_coordinates")
|
||||||
|
self.event_preferences = kwargs.pop("event_preferences")
|
||||||
|
self.event_blacklist = kwargs.pop("name")
|
||||||
|
self.group_size = kwargs.pop("group_size")
|
||||||
|
self.min_age = kwargs.pop("min_age")
|
||||||
|
self.max_age = kwargs.pop("max_age")
|
0
models/user.py
Normal file
0
models/user.py
Normal file
8
server.py
Normal file
8
server.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
from models import user, events
|
||||||
|
from apis import sbb
|
||||||
|
|
||||||
|
SBB = sbb.SBBWrapper()
|
||||||
|
|
||||||
|
ret = SBB.wrapper.locations.get(params={"name":"Zürich"})
|
||||||
|
print(ret[:3])
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user