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,17 +61,15 @@ class Vote(NamedTuple):
# todo expose vote type?
import json
from ..core.kompress import kopen
from ..core.kompress import ZipPath
from ..core.error import Res
def votes() -> Iterable[Res[Vote]]:
# 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
with kopen(
config.gdpr_path,
'analytics/qa\\vote.submit.json', # TODO what the fuck is wrong with these separators
encoding='utf-8-sig', # not sure why, but seems necessary for this data
) as fo:
for r in reversed(json.load(fo)): # they seem to be in decreasing order by default
path = ZipPath(config.gdpr_path)
votes_path = path / 'analytics' / 'qa\\vote.submit.json' # yes, it does contain a backslash...
j = json.loads(votes_path.read_text(encoding='utf-8-sig')) # not sure why, but this encoding seems necessary
for r in reversed(j): # they seem to be in decreasing order by default
# TODO implement check method that would go through all properties and emit errors?
yield Vote(r)