stackexchange.gdpr: use ZipPath instead of ad-hoc kopen

This commit is contained in:
Dima Gerasimov 2022-04-15 12:19:24 +01:00 committed by karlicoss
parent 706ec03a3f
commit e6e948de9c

View file

@ -61,19 +61,17 @@ class Vote(NamedTuple):
# todo expose vote type? # todo expose vote type?
import json import json
from ..core.kompress import kopen from ..core.kompress import ZipPath
from ..core.error import Res from ..core.error import Res
def votes() -> Iterable[Res[Vote]]: def votes() -> Iterable[Res[Vote]]:
# TODO there is also some site specific stuff in qa/ directory.. not sure if its' more detailed # TODO there is also some site specific stuff in qa/ directory.. not sure if its' more detailed
# todo should be defensive? not sure if present when user has no votes # todo should be defensive? not sure if present when user has no votes
with kopen( path = ZipPath(config.gdpr_path)
config.gdpr_path, votes_path = path / 'analytics' / 'qa\\vote.submit.json' # yes, it does contain a backslash...
'analytics/qa\\vote.submit.json', # TODO what the fuck is wrong with these separators j = json.loads(votes_path.read_text(encoding='utf-8-sig')) # not sure why, but this encoding seems necessary
encoding='utf-8-sig', # not sure why, but seems necessary for this data for r in reversed(j): # they seem to be in decreasing order by default
) as fo: # TODO implement check method that would go through all properties and emit errors?
for r in reversed(json.load(fo)): # they seem to be in decreasing order by default yield Vote(r)
# TODO implement check method that would go through all properties and emit errors?
yield Vote(r)
from ..core import stat, Stats from ..core import stat, Stats