diff options
| author | Yuval Adam <_@yuv.al> | 2020-09-27 17:40:12 +0300 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2020-09-27 17:40:12 +0300 |
| commit | b120c61343b2f738b7d19fde8c92fbcc377f9441 (patch) | |
| tree | 8c400d43c2a2882a968f038e83cd7b9c2c56e430 | |
| parent | 89894bf60a95e7f52717856053738a56d736d341 (diff) | |
Initial prediction rendering in template
| -rw-r--r-- | iss/predictions.py | 8 | ||||
| -rw-r--r-- | iss/server.py | 7 | ||||
| -rw-r--r-- | iss/templates/base.html | 3 | ||||
| -rw-r--r-- | 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 @@ </head> <body class="bg-near-black near-white"> <div class="pa4 mw7 center"> + <h1 class="f1 moon-gray">ISS Pass Predictions</h1> + <p class="light-red">Upcoming passes of the <a href="https://en.wikipedia.org/wiki/International_Space_Station" class="link red dim">International Space Station</a> at your location over the next 10 days.</p> + {% 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 %} -<h1 class="f1 moon-gray">ISS Pass Predictions</h1> -<p class="light-red">Upcoming passes of the <a href="https://en.wikipedia.org/wiki/International_Space_Station" class="link red dim">International Space Station</a> at your location over the next 10 days.</p> +<table class="ba tl pa1"> + <tr class="ba tc pa1 f3"> + <th colspan="2">Rise</th> + <th colspan="4">Culminate</th> + <th colspan="2">Set</th> + </tr> + <tr class="pa1 f4"> + <th>Time</th> + <th>Azimuth</th> + <th>Time</th> + <th>Azimuth</th> + <th>Elevation</th> + <th>Distance</th> + <th>Time</th> + <th>Azimuth</th> + </tr> + {% for pred in predictions %} + <tr class="pa1"> + <td>{{ pred.rise.time }}</td> + <td>{{ pred.rise.azimuth }}</td> + <td>{{ pred.culminate.time }}</td> + <td>{{ pred.culminate.azimuth }}</td> + <td>{{ pred.culminate.degrees }}</td> + <td>{{ pred.culminate.distance }}</td> + <td>{{ pred.set.time }}</td> + <td>{{ pred.set.azimuth }}</td> + </tr> + {% endfor %} + +</table> {% endblock %} |
