Download getFlightData.py from Pepsr/Chatbot: direct link, hf CLI and curl.
- Browser
- Download file 702 Bytes
-
https://huggingface.co/spaces/Pepsr/Chatbot/resolve/main/getFlightData.py
- Command line
-
hf download hf://spaces/Pepsr/Chatbot/getFlightData.py
-
curl -L -o getFlightData.py https://huggingface.co/spaces/Pepsr/Chatbot/resolve/main/getFlightData.py
702 Bytes
| import requests | |
| import os | |
| def getAccessToken(): | |
| url = "https://api.lufthansa.com/v1/oauth/token" | |
| data = { | |
| "client_id": os.environ['client_id'], | |
| "client_secret": os.environ['client_secret'], | |
| "grant_type": "client_credentials" | |
| } | |
| response = (requests.post(url, data=data)).json() | |
| return response["access_token"] | |
| def getFlightInfo(flight_number, date): | |
| token = getAccessToken() | |
| url = f"https://api.lufthansa.com/v1/operations/flightstatus/{flight_number}/{date}" | |
| headers = { | |
| "Authorization": f"Bearer {token}", | |
| "Accept": "application/json" | |
| } | |
| response = (requests.get(url, headers=headers)).json() | |
| print(response) | |
| return response | |