Chatbot / getFlightData.py
Pepsr's picture
api keys
8a8c396
Raw History Blame Contribute Delete
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