HPI/hypothesis/__init__.py
Dima Gerasimov fd2715ab74 initial
2018-08-06 19:56:31 +01:00

33 lines
777 B
Python

from functools import lru_cache
from kython import listdir_abs, json_load, JSONType
from typing import Dict, List, NamedTuple
from pytz import UTC
from datetime import datetime
import os
# TODO maybe, it should generate some kind of html snippet?
_PATH = '/L/backups/hypothesis/'
class Hypothesis(NamedTuple):
dt: datetime
text: str
tag: str
# TODO guarantee order?
def _iter():
last = max(listdir_abs(_PATH))
j: JSONType
with open(last, 'r') as fo:
j = json_load(fo)
for i in j:
dts = i['created']
title = ' '.join(i['document']['title'])
dt = datetime.strptime(dts[:-3] + dts[-2:], '%Y-%m-%dT%H:%M:%S.%f%z')
yield Hypothesis(dt, title, 'hyp')
@lru_cache()
def get_entries():
return list(_iter())