Better naming for api wrappers
This commit is contained in:
		
							
								
								
									
										53
									
								
								apis/sbb.py
									
									
									
									
									
								
							
							
						
						
									
										53
									
								
								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 |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |      | ||||||
|  |     def get_auth(self): | ||||||
|  |         token_query = { | ||||||
|  |             'grant_type': 'client_credentials', | ||||||
|  |             'client_id': 'af929f08', | ||||||
|  |             'client_secret': 'ae61e214f679558c28678d5c638c5725' | ||||||
|  |         } | ||||||
|  |  | ||||||
| SBB = tortilla.wrap('https://b2p-int.api.sbb.ch/api') |         response = requests.post('https://sso-int.sbb.ch/auth/realms/SBB_Public/protocol/openid-connect/token', data=token_query).json() | ||||||
| SBB.config.headers = get_auth() |  | ||||||
| # SBB.config.headers = { |  | ||||||
| #     "grant_type" : "client_credentials", |  | ||||||
| #     "client_secret" : "ae61e214f679558c28678d5c638c5725", |  | ||||||
| #     "client_id" : "af929f08pied!", |  | ||||||
| # } |  | ||||||
|  |  | ||||||
|  |         token = response["access_token"] | ||||||
| # Authorization: Bearer $accessToken' \ |         auth = { | ||||||
| #  -H 'Cache-Control: no-cache' \ |             'Authorization': f"Bearer {token}", | ||||||
| #  -H 'Accept: application/json' \ |             'X-Contract-Id': 'PLY223P', | ||||||
| #  -H 'X-Contract-Id: ABC1234' \ |             # 'X-Conversation-Id': str(conv_id), | ||||||
| #  -H 'X-Conversation-Id: e5eeb775-1e0e-4f89-923d-afa780ef844b |         } | ||||||
|  |         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
									
								
							
		Reference in New Issue
	
	Block a user
	 Remy Moll
					Remy Moll