From d25708b978b50c905b062eb8ba3970e48ae276e8 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Mon, 21 Sep 2020 23:29:10 +0300 Subject: Split server and prediction files --- Pipfile | 2 +- Procfile | 2 +- iss.py | 33 --------------------------------- iss/__init__.py | 0 iss/predictions.py | 23 +++++++++++++++++++++++ iss/server.py | 8 ++++++++ 6 files changed, 33 insertions(+), 35 deletions(-) delete mode 100644 iss.py create mode 100644 iss/__init__.py create mode 100644 iss/predictions.py create mode 100644 iss/server.py diff --git a/Pipfile b/Pipfile index 4495bbf..674b002 100644 --- a/Pipfile +++ b/Pipfile @@ -12,7 +12,7 @@ fastapi = "*" uvicorn = "*" [scripts] -server = "uvicorn iss:app" +server = "uvicorn iss.server:app" [requires] python_version = "3.8" diff --git a/Procfile b/Procfile index 61257a4..47d1b5d 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: uvicorn iss:app --host=0.0.0.0 --port=${PORT} +web: uvicorn iss.server:app --host=0.0.0.0 --port=${PORT} diff --git a/iss.py b/iss.py deleted file mode 100644 index 215b7c3..0000000 --- a/iss.py +++ /dev/null @@ -1,33 +0,0 @@ -from fastapi import FastAPI -from skyfield.api import Topos, load - -TEL_AVIV = Topos('32.0853 N', '34.7817 E') -ISS = "ISS (ZARYA)" - -def init_stations(): - stations_url = 'http://celestrak.com/NORAD/elements/stations.txt' - return load.tle_file(stations_url) - -def get_predictions(location=TEL_AVIV, satellite_name=ISS): - satellites = init_stations() - by_name = {sat.name: sat for sat in satellites} - satellite = by_name[satellite_name] - - ts = load.timescale() - t0 = ts.now() - t1 = ts.utc(2020, 9, 30) - - t, events = satellite.find_events(location, t0, t1, altitude_degrees=60.0) - for ti, event in zip(t, events): - name = ('rise above 30°', 'culminate', 'set below 30°')[event] - print(ti) - print(ti.utc_strftime('%Y %b %d %H:%M:%S'), name) - - - -app = FastAPI() - - -@app.get("/") -async def root(): - return {"message": "Hello World"} diff --git a/iss/__init__.py b/iss/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/iss/predictions.py b/iss/predictions.py new file mode 100644 index 0000000..fa4aeff --- /dev/null +++ b/iss/predictions.py @@ -0,0 +1,23 @@ +from skyfield.api import Topos, load + +TEL_AVIV = Topos('32.0853 N', '34.7817 E') +ISS = "ISS (ZARYA)" + +def init_stations(): + stations_url = 'http://celestrak.com/NORAD/elements/stations.txt' + return load.tle_file(stations_url) + +def get_predictions(location=TEL_AVIV, satellite_name=ISS): + satellites = init_stations() + by_name = {sat.name: sat for sat in satellites} + satellite = by_name[satellite_name] + + ts = load.timescale() + t0 = ts.now() + t1 = ts.utc(2020, 9, 30) + + t, events = satellite.find_events(location, t0, t1, altitude_degrees=60.0) + for ti, event in zip(t, events): + name = ('rise above 30°', 'culminate', 'set below 30°')[event] + print(ti) + print(ti.utc_strftime('%Y %b %d %H:%M:%S'), name) diff --git a/iss/server.py b/iss/server.py new file mode 100644 index 0000000..ee60be1 --- /dev/null +++ b/iss/server.py @@ -0,0 +1,8 @@ +from fastapi import FastAPI + +app = FastAPI() + + +@app.get("/") +async def root(): + return {"message": "Hello World"} -- cgit v1.3.1