pissflaps

This commit is contained in:
David Rice
2026-04-16 20:00:38 +01:00
parent 051f3535d7
commit 36fc73a6d5

View File

@@ -97,8 +97,10 @@ def _fetch_weather(lat: float, lon: float) -> None:
now = datetime.now() now = datetime.now()
hours = [] hours = []
for i, ts in enumerate(hourly['time']): for i, ts in enumerate(hourly['time']):
if len(hours) >= 5:
break
t = datetime.strptime(ts, '%Y-%m-%dT%H:%M') t = datetime.strptime(ts, '%Y-%m-%dT%H:%M')
if t < now or t.date() != now.date(): if t <= now:
continue continue
hours.append({ hours.append({
'label': t.strftime('%-I%p').lower(), 'label': t.strftime('%-I%p').lower(),
@@ -211,17 +213,18 @@ def draw_weather(surface: pygame.Surface, fonts: dict, x: int, y: int) -> None:
surface.blit(fonts['tiny'].render(row2_fn(item), True, WHITE), (cx, start_y + row)) surface.blit(fonts['tiny'].render(row2_fn(item), True, WHITE), (cx, start_y + row))
surface.blit(fonts['tiny'].render(row3_fn(item), True, DIM_GRAY), (cx, start_y + 2*row)) surface.blit(fonts['tiny'].render(row3_fn(item), True, DIM_GRAY), (cx, start_y + 2*row))
# Town name header # Town name header (small font — bigger than the grid text)
town_h = fonts['small'].get_height()
if town: if town:
surface.blit(fonts['tiny'].render(town, True, GRAY), (x, y)) surface.blit(fonts['small'].render(town, True, GRAY), (x, y))
if not week: if not week:
surface.blit(fonts['tiny'].render('Loading…', True, DIM_GRAY), (x, y + row)) surface.blit(fonts['tiny'].render('Loading…', True, DIM_GRAY), (x, y + town_h + 4))
return return
# 5-day section # 5-day section
_col(week, _col(week,
y + row + 2, y + town_h + 4,
lambda d: 'Today' if d['day'] == 'Today' else d['day'][:3], lambda d: 'Today' if d['day'] == 'Today' else d['day'][:3],
lambda d: f"{d['high']}°/{d['low']}°", lambda d: f"{d['high']}°/{d['low']}°",
lambda d: _trunc(d['desc'])) lambda d: _trunc(d['desc']))
@@ -229,7 +232,7 @@ def draw_weather(surface: pygame.Surface, fonts: dict, x: int, y: int) -> None:
# 5-hour section # 5-hour section
if hours: if hours:
_col(hours[:_WEATHER_COLS], _col(hours[:_WEATHER_COLS],
y + row + 2 + 3*row + 8, y + town_h + 4 + 3*row + 8,
lambda h: h['label'], lambda h: h['label'],
lambda h: f"{h['temp']}°", lambda h: f"{h['temp']}°",
lambda h: _trunc(h['desc'])) lambda h: _trunc(h['desc']))
@@ -321,7 +324,7 @@ def main() -> None:
draw_clock(screen, fonts, 20, clock_y) draw_clock(screen, fonts, 20, clock_y)
draw_weather(screen, fonts, weather_x, draw_weather(screen, fonts, weather_x,
clock_y - fonts['tiny'].get_height() - 2) clock_y - fonts['small'].get_height() - 4)
draw_dot(screen, W // 2, dot_y) draw_dot(screen, W // 2, dot_y)
pygame.display.flip() pygame.display.flip()