# HG changeset patch # User Paul Fisher # Date 1743537261 14400 # Node ID b77c8e7d2742334aea6dfe0ac44f97fc217e5205 # Parent d5a18ecebf4768cb44d5c6c56650e9f3b83622a6 Use zoneinfo rather than pytz. diff -r d5a18ecebf47 -r b77c8e7d2742 pyproject.toml --- a/pyproject.toml Tue Apr 01 15:46:16 2025 -0400 +++ b/pyproject.toml Tue Apr 01 15:54:21 2025 -0400 @@ -5,13 +5,12 @@ [project] name = "weather-server" dynamic = ["version"] -requires-python = ">=3.7" +requires-python = ">=3.9" dependencies = [ "attrs", "flask", "flup", "pymongo", - "pytz", ] [tool.hatch.version] diff -r d5a18ecebf47 -r b77c8e7d2742 weather_server/common.py --- a/weather_server/common.py Tue Apr 01 15:46:16 2025 -0400 +++ b/weather_server/common.py Tue Apr 01 15:54:21 2025 -0400 @@ -3,10 +3,9 @@ import typing as t import bson -import pytz BSON_OPTIONS = bson.DEFAULT_CODEC_OPTIONS.with_options( - tz_aware=True, tzinfo=pytz.UTC) + tz_aware=True, tzinfo=datetime.UTC) def bson_encode(data: t.Dict[str, t.Any]) -> bytes: @@ -29,4 +28,4 @@ def utc_now(): - return datetime.datetime.utcnow().replace(tzinfo=pytz.UTC) + return datetime.datetime.now(datetime.UTC) diff -r d5a18ecebf47 -r b77c8e7d2742 weather_server/locations.py --- a/weather_server/locations.py Tue Apr 01 15:46:16 2025 -0400 +++ b/weather_server/locations.py Tue Apr 01 15:54:21 2025 -0400 @@ -4,8 +4,7 @@ import datetime import pathlib import typing as t - -import pytz +import zoneinfo from . import logfile from . import types @@ -61,9 +60,9 @@ def timezone(self) -> datetime.tzinfo: try: - return pytz.timezone(self.tz_name) - except pytz.UnknownTimeZoneError: - return pytz.UTC + return zoneinfo.ZoneInfo(self.tz_name) + except zoneinfo.ZoneInfoNotFoundError: + return datetime.UTC def __repr__(self) -> str: return f'' diff -r d5a18ecebf47 -r b77c8e7d2742 weather_server/logfile.py --- a/weather_server/logfile.py Tue Apr 01 15:46:16 2025 -0400 +++ b/weather_server/logfile.py Tue Apr 01 15:54:21 2025 -0400 @@ -1,7 +1,6 @@ """The part which handles writing things out and reading things in from CSV. """ -import attr import collections import concurrent.futures as futures import contextlib @@ -11,11 +10,11 @@ import threading import typing as t +import attr import bson from . import common - # The number of entries to keep in memory without reading from disk. CACHED_ENTRIES = 16384 diff -r d5a18ecebf47 -r b77c8e7d2742 weather_server/logfile_test.py --- a/weather_server/logfile_test.py Tue Apr 01 15:46:16 2025 -0400 +++ b/weather_server/logfile_test.py Tue Apr 01 15:54:21 2025 -0400 @@ -6,14 +6,13 @@ import unittest import bson -import pytz from . import common from . import logfile def ts(n): - return datetime.datetime.utcfromtimestamp(n).replace(tzinfo=pytz.UTC) + return datetime.datetime.fromtimestamp(n, datetime.UTC) class LoggerTest(unittest.TestCase): diff -r d5a18ecebf47 -r b77c8e7d2742 weather_server/server.py --- a/weather_server/server.py Tue Apr 01 15:46:16 2025 -0400 +++ b/weather_server/server.py Tue Apr 01 15:54:21 2025 -0400 @@ -5,7 +5,6 @@ import bson import flask -import pytz from . import common from . import locations @@ -43,7 +42,7 @@ entries = tuple(reader) except (KeyError, bson.InvalidBSON): flask.abort(400) - now = datetime.datetime.now(tz=pytz.UTC) + now = datetime.datetime.now(tz=datetime.UTC) loc.record(entries, now) return flask.jsonify({'status': 'OK'}) @@ -59,7 +58,7 @@ date = tz.normalize(last_reading.sample_time.astimezone(tz)) else: date = None - now = datetime.datetime.now(tz=pytz.UTC) + now = datetime.datetime.now(tz=datetime.UTC) diff = (now - date) if date else None is_recent = diff and diff < datetime.timedelta(hours=12) return flask.render_template( @@ -67,7 +66,7 @@ location=loc, last_reading=last_reading, date=date, - date_format=f'%H:%M' if is_recent else '%Y-%m-%d %H:%M') + date_format='%H:%M' if is_recent else '%Y-%m-%d %H:%M') @app.route('//recent') def recent(location: str): diff -r d5a18ecebf47 -r b77c8e7d2742 weather_server/types.py --- a/weather_server/types.py Tue Apr 01 15:46:16 2025 -0400 +++ b/weather_server/types.py Tue Apr 01 15:54:21 2025 -0400 @@ -6,7 +6,6 @@ import attr - T = t.TypeVar('T')