From b120c61343b2f738b7d19fde8c92fbcc377f9441 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Sun, 27 Sep 2020 17:40:12 +0300 Subject: Initial prediction rendering in template --- iss/predictions.py | 8 +++++++- iss/server.py | 7 ++++++- iss/templates/base.html | 3 +++ iss/templates/index.html | 32 ++++++++++++++++++++++++++++++-- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/iss/predictions.py b/iss/predictions.py index 29bcf2c..1bdd10e 100644 --- a/iss/predictions.py +++ b/iss/predictions.py @@ -77,7 +77,13 @@ class Predictions(object): # docs mention the possibilibity of several culminations # https://rhodesmill.org/skyfield/earth-satellites.html#finding-when-a-satellite-rises-and-sets # but this doesn't seem to happen in our case - return list(chunks(ts, 3)) + res = list(chunks(ts, 3)) + + if len(res[-1]) != 3: + # truncate the last event in case it's a partial one + res = res[:-1] + + return res def get_predictions(self): preds = self.get_prediction_events() diff --git a/iss/server.py b/iss/server.py index 620e070..8d5c273 100644 --- a/iss/server.py +++ b/iss/server.py @@ -2,6 +2,8 @@ from fastapi import FastAPI, Request from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates +from .predictions import Predictions + app = FastAPI() app.mount("/static", StaticFiles(directory="iss/static"), name="static") @@ -11,4 +13,7 @@ templates = Jinja2Templates(directory="iss/templates") @app.get("/") async def home(request: Request): - return templates.TemplateResponse("index.html", {"request": request}) + preds = Predictions(34, 32).get_predictions() + return templates.TemplateResponse( + "index.html", {"request": request, "predictions": preds} + ) diff --git a/iss/templates/base.html b/iss/templates/base.html index 546b27a..952f948 100644 --- a/iss/templates/base.html +++ b/iss/templates/base.html @@ -12,6 +12,9 @@
+

ISS Pass Predictions

+

Upcoming passes of the International Space Station at your location over the next 10 days.

+ {% block content %} {% endblock %} diff --git a/iss/templates/index.html b/iss/templates/index.html index a02b312..6c93254 100644 --- a/iss/templates/index.html +++ b/iss/templates/index.html @@ -1,6 +1,34 @@ {% extends "base.html" %} {% block content %} -

ISS Pass Predictions

-

Upcoming passes of the International Space Station at your location over the next 10 days.

+ + + + + + + + + + + + + + + + + {% for pred in predictions %} + + + + + + + + + + + {% endfor %} + +
RiseCulminateSet
TimeAzimuthTimeAzimuthElevationDistanceTimeAzimuth
{{ pred.rise.time }}{{ pred.rise.azimuth }}{{ pred.culminate.time }}{{ pred.culminate.azimuth }}{{ pred.culminate.degrees }}{{ pred.culminate.distance }}{{ pred.set.time }}{{ pred.set.azimuth }}
{% endblock %} -- cgit v1.3.1