Better naming for api wrappers
This commit is contained in:
parent
23aff0ddf0
commit
fe015d75e7
29
apis/sbb.py
29
apis/sbb.py
@ -2,7 +2,14 @@ import tortilla
|
||||
import requests
|
||||
|
||||
|
||||
def get_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()
|
||||
|
||||
|
||||
|
||||
def get_auth(self):
|
||||
token_query = {
|
||||
'grant_type': 'client_credentials',
|
||||
'client_id': 'af929f08',
|
||||
@ -19,23 +26,3 @@ def get_auth():
|
||||
}
|
||||
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"}))
|
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