diff --git a/adsb.py b/adsb.py new file mode 100644 index 0000000..e05b357 --- /dev/null +++ b/adsb.py @@ -0,0 +1,16 @@ +import requests +import pprint + + +def get_plane_data(icao_code): + + base_url = "https://api.adsb.lol/v2/" + api_url = "hex/" + + url = base_url + api_url + req = requests.get(url+icao_code) + pprint.pprint(req.json()) + return req.json() + +get_plane_data("4BAA84") + diff --git a/airplaneslive.py b/airplaneslive.py new file mode 100644 index 0000000..4ea0e9d --- /dev/null +++ b/airplaneslive.py @@ -0,0 +1,20 @@ +import requests +from pprint import pprint + +def get_plane_data(icao_code): + base_url = "https://api.airplanes.live/v2/" + api_url = "icao/" + url = f"{base_url}{api_url}{icao_code}" + + # Make the request + req = requests.get(url) + + jsondata = req.json() # Return JSON data from response + flight = jsondata["ac"][0] + + pprint(flight) + + return flight + +get_plane_data("4BAA84") + diff --git a/data_api.py b/data_api.py new file mode 100644 index 0000000..42c637d --- /dev/null +++ b/data_api.py @@ -0,0 +1,52 @@ +from fastapi import FastAPI, HTTPException +from fastapi.middleware.cors import CORSMiddleware +import requests +from fastapi.staticfiles import StaticFiles + +app = FastAPI() + +# Define allowed origins and configure CORS middleware +origins = [ + "http://127.0.0.1:8000", + "http://localhost:8000" +] + +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + + +# Function to fetch plane data from external API +def get_plane_data(icao_code): + base_url = "https://api.airplanes.live/v2/" + api_url = "icao/" + url = f"{base_url}{api_url}{icao_code}" + + # Make the request + req = requests.get(url) + + # Check response status code + if req.status_code != 200: + raise HTTPException(status_code=req.status_code, detail="Error fetching data") + + jsondata = req.json() # Return JSON data from response + + if len(jsondata["ac"]) > 0: + flight = jsondata["ac"][0] + return flight + else: + return "No flight found" + + +# Endpoint to fetch plane data +@app.get("/plane/{icao_code}") +async def read_plane_data(icao_code: str): + return get_plane_data(icao_code) + +app.mount('/static', StaticFiles(directory='static',html=True)) + +# uvicorn data_api:app --reload diff --git a/opensky.py b/opensky.py new file mode 100644 index 0000000..87318d0 --- /dev/null +++ b/opensky.py @@ -0,0 +1,31 @@ +import datetime +import requests +import pprint + +current_time = datetime.datetime.now(datetime.UTC) +print(current_time) +recent_time = current_time - datetime.timedelta(seconds=60) +print(recent_time) + +# to unix timestamp +unix_time = recent_time.timestamp() +print(unix_time) + +base_url = "https://opensky-network.org/api" +api_url = "/states/all" +url = base_url + api_url +print(url) + +""" +example_query = requests.get(f"https://opensky-network.org/api/states/all?lamin=45.8389&lomin=5.9962&lamax=47.8229&lomax=10.5226") +pprint.pprint(example_query.json()) +""" + + +icao_code = "4BAA84" +params = { + "time": int(unix_time), + "icao24": icao_code, +} +req = requests.get(url, params=params) +pprint.pprint(req.json()) diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..8e38cba --- /dev/null +++ b/static/index.html @@ -0,0 +1,104 @@ + + +
+ +