diff --git a/doc/MODULES.org b/doc/MODULES.org index aafc670..a6dcd9d 100644 --- a/doc/MODULES.org +++ b/doc/MODULES.org @@ -160,7 +160,7 @@ For an extensive/complex example, you can check out ~@seanbreckenridge~'s [[http - you might trust your original timezone, or it might just be UTC, and you want to use something more reasonable #+begin_src python - Policy = Literal[ + TzPolicy = Literal[ 'keep' , # if datetime is tz aware, just preserve it 'convert', # if datetime is tz aware, convert to provider's tz 'throw' , # if datetime is tz aware, throw exception diff --git a/my/ip/all.py b/my/ip/all.py index a7ac679..b21b543 100644 --- a/my/ip/all.py +++ b/my/ip/all.py @@ -11,11 +11,12 @@ REQUIRES = ["git+https://github.com/seanbreckenridge/ipgeocache"] from typing import Iterator -from my.core.common import Stats +from my.core.common import Stats, warn_if_empty from .common import IP +@warn_if_empty def ips() -> Iterator[IP]: yield from () diff --git a/my/ip/common.py b/my/ip/common.py index fb57406..82008e2 100644 --- a/my/ip/common.py +++ b/my/ip/common.py @@ -24,7 +24,7 @@ class IP(NamedTuple): return ipgeocache.get(self.addr) @property - def tz(self) -> str: + def tzname(self) -> str: tz: str = self.ipgeocache()["timezone"] return tz diff --git a/my/location/common.py b/my/location/common.py index b5cf3bd..b0676ec 100644 --- a/my/location/common.py +++ b/my/location/common.py @@ -10,8 +10,8 @@ LatLon = Tuple[float, float] # TODO: add timezone to this? can use timezonefinder in tz provider instead though class Location(NamedTuple): - lon: float lat: float + lon: float dt: datetime accuracy: Optional[float] elevation: Optional[float] diff --git a/my/time/tz/via_location.py b/my/time/tz/via_location.py index cd81358..abfe8c2 100644 --- a/my/time/tz/via_location.py +++ b/my/time/tz/via_location.py @@ -106,8 +106,23 @@ def most_common(lst: List[DayWithZone]) -> DayWithZone: return res -# refresh _iter_tzs once per day -- don't think a better depends_on is possible dynamically -@mcachew(logger=logger, depends_on=lambda: str(date.today())) +def _iter_tz_depends_on() -> str: + """ + Since you might get new data which specifies a new timezone sometime + in the day, this causes _iter_tzs to refresh every 6 hours, like: + 2022-04-26_00 + 2022-04-26_06 + 2022-04-26_12 + 2022-04-26_18 + """ + day = str(date.today()) + hr = datetime.now().hour + hr_truncated = hr // 6 * 6 + return "{}_{}".format(day, hr_truncated) + + +# refresh _iter_tzs every 6 hours -- don't think a better depends_on is possible dynamically +@mcachew(logger=logger, depends_on=_iter_tz_depends_on) def _iter_tzs() -> Iterator[DayWithZone]: # since we have no control over what order the locations are returned, # we need to sort them first before we can do a groupby