-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
30 lines (22 loc) · 771 Bytes
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from flask import Flask, redirect, render_template, request, Blueprint, jsonify
import requests
from dotenv import load_dotenv
import os
flight_ap = Blueprint('api', __name__)
#Aviation Stack API
SOURCE_URL = os.getenv('SOURCE')
KEY = os.getenv('AERO_API_KEY')
HEADERS = {'x-apikey': KEY}
def query_flight(ident, ident_type='designator'):
endpoint = f"{SOURCE_URL}/flights/{ident}"
params = {
'ident_type': ident_type,
'max_pages': 1
}
response = requests.get(endpoint, headers=HEADERS, params=params)
if response.status_code == 200:
data = response.json()
return data
else:
print(f"Error: {response.status_code}, {response.text}")
return {'error': 'Failed to fetch flight information'}