Compare commits

...

4 commits

3 changed files with 122 additions and 5 deletions

6
Dockerfile Normal file
View file

@ -0,0 +1,6 @@
FROM python:3.13-slim-bookworm
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
ADD . /app
WORKDIR /app
RUN uv sync --frozen --no-cache
CMD ["/app/.venv/bin/fastapi", "run", "main.py", "--port", "8887"]

27
main.py
View file

@ -27,16 +27,33 @@ CONFIG = {
} }
def format_datetime(dt): def format_date(dt):
return dt.astimezone(eastern).isoformat() dt = dt.astimezone(eastern)
return dt.strftime("%a %d").lower()
def format_time(dt): def format_time(dt):
dt = dt.astimezone(eastern)
return dt.strftime("%I:%M%p").lower() return dt.strftime("%I:%M%p").lower()
def format_date(dt): def format_datetime(dt):
return dt.strftime("%a %d").lower() dt = dt.astimezone(eastern)
return f"{format_date(dt)} {format_time(dt)}"
def pollen_desc(index):
if index < 2.5:
return f"{index} l"
elif index < 4.9:
return f"{index} l-m"
elif index < 7.3:
return f"{index} m"
elif index < 9.7:
return f"{index} m-h"
else:
return f"{index} h"
def relative_day_to_date(rel_dt): def relative_day_to_date(rel_dt):
@ -89,7 +106,7 @@ async def fetch_pollen(zipcode):
datetime.fromisoformat(data["ForecastDate"]) datetime.fromisoformat(data["ForecastDate"])
), ),
"periods": [ "periods": [
{"index": d["Index"], "period": relative_day_to_date(d["Type"])} {"index": pollen_desc(d["Index"]), "period": relative_day_to_date(d["Type"])}
for d in data["Location"]["periods"] for d in data["Location"]["periods"]
], ],
} }

94
template.liquid Normal file
View file

@ -0,0 +1,94 @@
<div class="columns">
<div class="column">
<span class="title title--small text--gray-4 text--center">fetched: {{ fetched_at }}</span>
{% for pollen in pollen %}
<span class="title title--small bg--black text--white text--center">pollen index</span>
<div class="richtext gap--xxsmall">
<p class="content content--small">forecast at {{pollen.forecast_date}}</p>
</div>
<table class="table table--condensed">
<thead>
<tr>
{% for period in pollen.periods %}
<th><span class="label label--small text--center">{{period.period}}</span></th>
{% endfor %}
</tr>
</thead>
<tbody>
<tr>
{% for period in pollen.periods %}
<td><span class="label label--small text--center">{{period.index}}</span></td>
{% endfor %}
</tr>
</tbody>
</table>
{% endfor %}
{% for weather in weather %}
<span class="title title--small bg--black text--white text--center">weather forecast</span>
<div class="richtext gap--xxsmall">
<p class="content content--small">forecast at {{weather.forecast_date}}</p>
</div>
<table class="table table--condensed">
<thead>
<tr>
<th><span class="label label--small w--16"></span></th>
{% for period in weather.periods %}
<th><span class="label label--small w--16 text--center">{{period.period}}</span></th>
{% endfor %}
</tr>
</thead>
<tbody>
<tr>
<td><span class="label label--small text--right">low</span></td>
{% for period in weather.periods %}
<td><span class="label label--small text--center">{{period.low}} F</span></td>
{% endfor %}
</tr>
<tr>
<td><span class="label label--small text--right">high</span></td>
{% for period in weather.periods %}
<td><span class="label label--small text--center">{{period.high}} F</span></td>
{% endfor %}
</tr>
<tr>
<td><span class="label label--small text--right">humidity</span></td>
{% for period in weather.periods %}
<td><span class="label label--small text--center">{{period.humidity}}%</span></td>
{% endfor %}
</tr>
<tr>
<td><span class="label label--small text--right">pressure</span></td>
{% for period in weather.periods %}
<td><span class="label label--small text--center">{{period.pressure}}</span></td>
{% endfor %}
</tr>
<tr>
<td><span class="label label--small text--right">sunrise</span></td>
{% for period in weather.periods %}
<td><span class="label label--small text--center">{{period.sunrise}}</span></td>
{% endfor %}
</tr>
<tr>
<td><span class="label label--small text--right">sunset</span></td>
{% for period in weather.periods %}
<td><span class="label label--small text--center">{{period.sunset}}</span></td>
{% endfor %}
</tr>
<tr>
<td><span class="label label--small text--right">desc</span></td>
{% for period in weather.periods %}
<td><span class="label label--small h--10 clamp--none text--center">{{period.desc}}</span></td>
{% endfor %}
</tr>
</tbody>
</table>
{% endfor %}
</div>
<div class="column">
{{ Content for column 2 }}
</div>
<div class="column">
{{ Content for column 3 }}
</div>
</div>