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
|
||||
|
||||
|
||||
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
|
||||
class SBBWrapper:
|
||||
def __init__(self) -> None:
|
||||
self.wrapper = tortilla.wrap('https://b2p-int.api.sbb.ch/api')
|
||||
self.wrapper.config.headers = self.get_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!",
|
||||
# }
|
||||
def get_auth(self):
|
||||
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()
|
||||
|
||||
# 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
|
||||
token = response["access_token"]
|
||||
auth = {
|
||||
'Authorization': f"Bearer {token}",
|
||||
'X-Contract-Id': 'PLY223P',
|
||||
# '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
Loading…
x
Reference in New Issue
Block a user