tz -> zone, update iter_tzs depends on, misc changes
This commit is contained in:
parent
8ab67d4d26
commit
62dd6712f3
5 changed files with 22 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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 ()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue