misc: replace uses of pytz.utc with timezone.utc where it makes sense
This commit is contained in:
parent
c91534b966
commit
c12224af74
9 changed files with 24 additions and 42 deletions
|
@ -5,8 +5,7 @@ Just a demo module for testing and documentation purposes
|
|||
from .core import Paths, PathIsh
|
||||
|
||||
from typing import Optional
|
||||
from datetime import tzinfo
|
||||
import pytz
|
||||
from datetime import tzinfo, timezone
|
||||
|
||||
from my.config import demo as user_config
|
||||
from dataclasses import dataclass
|
||||
|
@ -16,7 +15,7 @@ from dataclasses import dataclass
|
|||
class demo(user_config):
|
||||
data_path: Paths
|
||||
username: str
|
||||
timezone: tzinfo = pytz.utc
|
||||
timezone: tzinfo = timezone.utc
|
||||
|
||||
external: Optional[PathIsh] = None
|
||||
|
||||
|
|
|
@ -4,11 +4,9 @@ Github events and their metadata: comments/issues/pull requests
|
|||
from ..core import __NOT_HPI_MODULE__
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional, NamedTuple, Iterable, Set, Tuple
|
||||
|
||||
import pytz
|
||||
|
||||
from ..core import warn_if_empty, LazyLogger
|
||||
from ..core.error import Res
|
||||
|
||||
|
@ -48,7 +46,7 @@ def merge_events(*sources: Results) -> Results:
|
|||
|
||||
def parse_dt(s: str) -> datetime:
|
||||
# TODO isoformat?
|
||||
return pytz.utc.localize(datetime.strptime(s, '%Y-%m-%dT%H:%M:%SZ'))
|
||||
return datetime.strptime(s, '%Y-%m-%dT%H:%M:%SZ').replace(tzinfo=timezone.utc)
|
||||
|
||||
|
||||
# experimental way of supportint event ids... not sure
|
||||
|
|
|
@ -5,12 +5,11 @@ Google Takeout exports: browsing history, search/youtube/google play activity
|
|||
from enum import Enum
|
||||
import re
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from html.parser import HTMLParser
|
||||
from typing import List, Optional, Any, Callable, Iterable, Tuple
|
||||
from collections import OrderedDict
|
||||
from urllib.parse import unquote
|
||||
import pytz
|
||||
|
||||
from ...core.time import abbr_to_timezone
|
||||
|
||||
|
@ -30,7 +29,7 @@ def parse_dt(s: str) -> datetime:
|
|||
# old takeouts didn't have timezone
|
||||
# hopefully it was utc? Legacy, so no that much of an issue anymore..
|
||||
# todo although maybe worth adding timezone from location provider?
|
||||
tz = pytz.utc
|
||||
tz = timezone.utc
|
||||
else:
|
||||
s, tzabbr = s.rsplit(maxsplit=1)
|
||||
tz = abbr_to_timezone(tzabbr)
|
||||
|
|
|
@ -17,13 +17,11 @@ from .core.cfg import make_config
|
|||
config = make_config(lastfm)
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import NamedTuple, Sequence, Iterable
|
||||
|
||||
import pytz
|
||||
|
||||
from .core.common import mcachew, Json, get_files
|
||||
|
||||
|
||||
|
@ -44,7 +42,7 @@ class Scrobble(NamedTuple):
|
|||
@property
|
||||
def dt(self) -> datetime:
|
||||
ts = int(self.raw['date'])
|
||||
return datetime.fromtimestamp(ts, tz=pytz.utc)
|
||||
return datetime.fromtimestamp(ts, tz=timezone.utc)
|
||||
|
||||
@property
|
||||
def artist(self) -> str:
|
||||
|
|
|
@ -112,9 +112,8 @@ def upvoted() -> Iterator[Upvote]:
|
|||
|
||||
from typing import Dict, Iterable, Iterator, NamedTuple
|
||||
from functools import lru_cache
|
||||
import pytz
|
||||
import re
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from multiprocessing import Pool
|
||||
|
||||
# TODO hmm. apparently decompressing takes quite a bit of time...
|
||||
|
@ -151,7 +150,7 @@ def _get_bdate(bfile: Path) -> datetime:
|
|||
stem = stem.replace('T', '').replace('Z', '') # adapt for arctee
|
||||
match = RE.search(stem)
|
||||
assert match is not None
|
||||
bdt = pytz.utc.localize(datetime.strptime(match.group(1), "%Y%m%d%H%M%S"))
|
||||
bdt = datetime.strptime(match.group(1), "%Y%m%d%H%M%S").replace(tzinfo=timezone.utc)
|
||||
return bdt
|
||||
|
||||
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
"""
|
||||
[[https://roamresearch.com][Roam]] data
|
||||
"""
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from itertools import chain
|
||||
import re
|
||||
from typing import NamedTuple, Iterator, List, Optional
|
||||
|
||||
import pytz
|
||||
|
||||
from .core import get_files, LazyLogger, Json
|
||||
|
||||
from my.config import roamresearch as config
|
||||
|
@ -38,7 +36,7 @@ class Node(NamedTuple):
|
|||
def created(self) -> datetime:
|
||||
ct = self.raw.get(Keys.CREATED)
|
||||
if ct is not None:
|
||||
return datetime.fromtimestamp(ct / 1000, tz=pytz.utc)
|
||||
return datetime.fromtimestamp(ct / 1000, tz=timezone.utc)
|
||||
# ugh. daily notes don't have create time for some reason???
|
||||
|
||||
title = self.title
|
||||
|
@ -50,13 +48,13 @@ class Node(NamedTuple):
|
|||
return self.edited # fallback TODO log?
|
||||
# strip off 'th'/'rd' crap
|
||||
dts = m.group(1) + ' ' + m.group(2) + ' ' + m.group(3)
|
||||
dt = datetime.strptime(dts, '%B %d %Y')
|
||||
return pytz.utc.localize(dt)
|
||||
dt = datetime.strptime(dts, '%B %d %Y').replace(tzinfo=timezone.utc)
|
||||
return dt
|
||||
|
||||
@property
|
||||
def edited(self) -> datetime:
|
||||
rt = self.raw[Keys.EDITED]
|
||||
return datetime.fromtimestamp(rt / 1000, tz=pytz.utc)
|
||||
return datetime.fromtimestamp(rt / 1000, tz=timezone.utc)
|
||||
|
||||
@property
|
||||
def title(self) -> Optional[str]:
|
||||
|
|
|
@ -1,23 +1,21 @@
|
|||
"""
|
||||
Feedly RSS reader
|
||||
"""
|
||||
|
||||
from my.config import feedly as config
|
||||
|
||||
from datetime import datetime, timezone
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Sequence
|
||||
from typing import Iterable, Sequence
|
||||
|
||||
from ..core.common import listify, get_files
|
||||
from .common import Subscription
|
||||
from .common import Subscription, SubscriptionState
|
||||
|
||||
|
||||
def inputs() -> Sequence[Path]:
|
||||
return get_files(config.export_path)
|
||||
|
||||
|
||||
import json
|
||||
|
||||
|
||||
@listify
|
||||
def parse_file(f: Path):
|
||||
raw = json.loads(f.read_text())
|
||||
|
@ -33,14 +31,9 @@ def parse_file(f: Path):
|
|||
)
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Iterable
|
||||
from .common import SubscriptionState
|
||||
def states() -> Iterable[SubscriptionState]:
|
||||
import pytz
|
||||
for f in inputs():
|
||||
dts = f.stem.split('_')[-1]
|
||||
dt = datetime.strptime(dts, '%Y%m%d%H%M%S')
|
||||
dt = pytz.utc.localize(dt)
|
||||
dt = datetime.strptime(dts, '%Y%m%d%H%M%S').replace(tzinfo=timezone.utc)
|
||||
subs = parse_file(f)
|
||||
yield dt, subs
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from itertools import islice
|
||||
import pytz
|
||||
|
||||
|
@ -43,7 +43,7 @@ def test_myactivity_search() -> None:
|
|||
results = list(read_html(tpath, path))
|
||||
|
||||
res = (
|
||||
datetime(year=2018, month=12, day=17, hour=8, minute=16, second=18, tzinfo=pytz.utc),
|
||||
datetime(year=2018, month=12, day=17, hour=8, minute=16, second=18, tzinfo=timezone.utc),
|
||||
'https://en.wikipedia.org/wiki/Emmy_Noether&usg=AFQjCNGrSW-iDnVA2OTcLsG3I80H_a6y_Q',
|
||||
'Emmy Noether - Wikipedia',
|
||||
)
|
||||
|
|
|
@ -3,11 +3,9 @@ from my.tests.common import skip_if_not_karlicoss as pytestmark
|
|||
# should make lazy loading the default..
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
import json
|
||||
|
||||
import pytz
|
||||
|
||||
|
||||
def test_tweet() -> None:
|
||||
from my.twitter.archive import Tweet
|
||||
|
@ -45,7 +43,7 @@ def test_tweet() -> None:
|
|||
"""
|
||||
t = Tweet(json.loads(raw), screen_name='whatever')
|
||||
assert t.permalink is not None
|
||||
assert t.dt == datetime(year=2012, month=8, day=30, hour=7, minute=12, second=48, tzinfo=pytz.utc)
|
||||
assert t.dt == datetime(year=2012, month=8, day=30, hour=7, minute=12, second=48, tzinfo=timezone.utc)
|
||||
assert t.text == 'this is a test tweet'
|
||||
assert t.tid == '2328934829084'
|
||||
assert t.entities is not None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue