Skip to content

Commit 74fdd73

Browse files
author
Agent
committed
Merge branch 'main' into add-nominatim-metrics
2 parents f89d7b3 + 8882317 commit 74fdd73

File tree

6 files changed

+31
-28
lines changed

6 files changed

+31
-28
lines changed

fingr/config.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import os
44
import secrets
5-
from typing import List
65

76
from .logging import get_logger
87

@@ -27,10 +26,10 @@ def load_user_agent() -> str:
2726
return "default fingr useragent"
2827

2928

30-
def load_motd_list() -> List[str]:
29+
def load_motd_list() -> list[str]:
3130
"""Load message of the day list from file."""
3231
motdfile: str = "motd.txt"
33-
motdlist: List[str] = []
32+
motdlist: list[str] = []
3433
count: int = 0
3534

3635
try:
@@ -51,17 +50,17 @@ def load_motd_list() -> List[str]:
5150
return motdlist
5251

5352

54-
def random_message(messages: List[str]) -> str:
53+
def random_message(messages: list[str]) -> str:
5554
"""Pick a random message of the day."""
5655
if len(messages) == 0:
5756
return ""
5857
return "[" + messages[secrets.randbelow(len(messages))] + "]\n"
5958

6059

61-
def load_deny_list() -> List[str]:
60+
def load_deny_list() -> list[str]:
6261
"""Load list of IPs to deny service from file."""
6362
denyfile: str = "deny.txt"
64-
denylist: List[str] = []
63+
denylist: list[str] = []
6564
count: int = 0
6665

6766
try:

fingr/formatting.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import datetime
44
import math
5-
from typing import Any, Dict, List, Optional, Union
5+
from typing import Any, Optional, Union
66

77
import pysolar.solar # type: ignore[import-untyped]
88
import pytz # type: ignore[import-untyped]
@@ -41,7 +41,7 @@ def format_meteogram(
4141
output: str = ""
4242

4343
# Init graph
44-
graph: Dict[int, str] = {}
44+
graph: dict[int, str] = {}
4545
tempheight: int = 11
4646
timeline: int = 13
4747
windline: int = 15
@@ -98,7 +98,7 @@ def format_meteogram(
9898
templow = temphigh - 1
9999

100100
# Create temp range
101-
temps: List[int] = []
101+
temps: list[int] = []
102102
for t in range(int(temphigh), int(templow) - 1, tempstep):
103103
temps.append(t)
104104

@@ -118,7 +118,7 @@ def format_meteogram(
118118
pass
119119

120120
# create rainaxis #TODO: make this scale
121-
rainaxis: List[str] = []
121+
rainaxis: list[str] = []
122122
for r in range(rainheight, 0, rainstep):
123123
if r <= rainhigh: # + 1
124124
rainaxis.append(f"{r:2.0f} mm ")
@@ -181,7 +181,7 @@ def format_meteogram(
181181
for i in range(1, tempheight): # draw temp
182182
try:
183183
# parse out numbers to be compared
184-
temptomatch: List[int] = [temperature]
184+
temptomatch: list[int] = [temperature]
185185
tempingraph: int = int(graph[i][:3].strip())
186186

187187
if tempstep < -1: # TODO: this should scale higher than one step
@@ -225,12 +225,6 @@ def format_meteogram(
225225
else: # if int(item['symbolnumber']) in [5,6,9,10,11,14]: #rain
226226
rainsymbol = "|"
227227

228-
# if 0 > int(item['temperature']): #rain but cold
229-
# rainsymbol = "*"
230-
231-
# if verbose:
232-
# print("rainmax: ", rainmax,"i",i,"rain",rain)
233-
234228
# if overflow, print number at top
235229
if rain > 10 and i == 1:
236230
rainsymbol = f"{rain:2.0f}"
@@ -268,14 +262,14 @@ def format_meteogram(
268262

269263

270264
def print_units(
271-
graph: Dict[int, str],
265+
graph: dict[int, str],
272266
screenwidth: int,
273267
imperial: bool,
274268
beaufort: bool,
275269
windline: int,
276270
windstrline: int,
277271
timeline: int,
278-
) -> Dict[int, str]:
272+
) -> dict[int, str]:
279273
"""Add units for rain, wind, etc."""
280274
graph[0] = " 'C" + str.rjust("Rain (mm) ", screenwidth - 3)
281275
if imperial:
@@ -306,7 +300,7 @@ def format_oneliner(
306300
offset: int = 0,
307301
wind_chill: bool = False,
308302
) -> str:
309-
"""Return a one-line weather forecast. TODO: remove json, respect windchill, imperial, etc."""
303+
"""Return a one-line weather forecast."""
310304
start_time: Optional[datetime.datetime] = None
311305
place: str = forecast.place.name
312306
next6: str = forecast.json["data"]["properties"]["timeseries"][0]["data"]["next_6_hours"]

fingr/location.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import datetime
44
import socket
5-
from typing import Any, Optional, Tuple, Union
5+
from typing import Any, Optional, Union
66

77
import pytz # type: ignore[import-untyped]
88
import redis
@@ -38,7 +38,7 @@ def get_timezone(lat: float, lon: float) -> Timezone:
3838

3939
def resolve_location(
4040
redis_client: RedisClient, geolocator: Optional[Nominatim], data: str = "Oslo/Norway"
41-
) -> Tuple[Optional[float], Optional[float], str, bool]:
41+
) -> tuple[Optional[float], Optional[float], str, bool]:
4242
"""Get coordinates from location name. Return lat, long, name, cached."""
4343
with track_time(location_resolution_duration):
4444
# Check if coordinates

fingr/server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import argparse
44
import asyncio
55
import sys
6-
from typing import Any, Optional, Tuple
6+
from typing import Any, Optional
77

88
import redis
99
from geopy.geocoders import Nominatim # type: ignore[import-untyped]
@@ -94,7 +94,7 @@ async def handle_request(reader: asyncio.StreamReader, writer: asyncio.StreamWri
9494
with track_time(request_duration):
9595
try:
9696
user_input: str = clean_input(data.decode())
97-
addr: Tuple[str, int] = writer.get_extra_info("peername") # type: ignore[assignment]
97+
addr: tuple[str, int] = writer.get_extra_info("peername") # type: ignore[assignment]
9898
screenwidth: int = 80
9999
wind_chill: bool = False
100100

@@ -259,7 +259,7 @@ async def start_server(args: argparse.Namespace) -> None:
259259
handle_request, args.host, args.port
260260
)
261261

262-
addr: Tuple[str, int] = server.sockets[0].getsockname() # type: ignore[assignment]
262+
addr: tuple[str, int] = server.sockets[0].getsockname() # type: ignore[assignment]
263263
logger.info("Server ready", host=addr[0], port=addr[1])
264264

265265
async with server:

fingr/weather.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Weather data fetching and processing."""
22

3-
from typing import Any, Tuple
3+
from typing import Any
44

55
from metno_locationforecast import Forecast, Place # type: ignore[import-untyped]
66

@@ -18,7 +18,7 @@
1818

1919
def fetch_weather(
2020
lat: float, lon: float, address: str = "", user_agent: str = ""
21-
) -> Tuple[Any, Any]:
21+
) -> tuple[Any, Any]:
2222
"""Get forecast data using metno-locationforecast."""
2323
with track_time(weather_fetch_duration):
2424
location: Place = Place(address, lat, lon)
@@ -44,6 +44,15 @@ def fetch_weather(
4444

4545

4646
def calculate_wind_chill(temperature: float, wind_speed: float) -> int:
47+
"""Calculate wind chill temperature using the formula.
48+
49+
Args:
50+
temperature: Temperature in Celsius
51+
wind_speed: Wind speed in m/s
52+
53+
Returns:
54+
Wind chill temperature as integer
55+
"""
4756
return int(
4857
13.12
4958
+ (0.615 * float(temperature))

fingr_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ def test_random_message(self):
7171

7272
def test_get_timezone(self):
7373
tz = get_timezone(lat=59, lon=11)
74-
self.assertEqual(tz.zone, "Europe/Oslo")
74+
# pytz timezone objects have a 'zone' attribute
75+
self.assertEqual(tz.zone, "Europe/Oslo") # type: ignore[attr-defined]
7576

7677
def test_sun_up(self):
7778
dt = datetime.datetime.fromtimestamp(1727987676, tz=pytz.timezone("UTC"))

0 commit comments

Comments
 (0)