From fd2715ab74630b0d8de63bee21336d55aff2c0b3 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Mon, 6 Aug 2018 19:56:31 +0100 Subject: [PATCH] initial --- hypothesis/__init__.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/hypothesis/__init__.py b/hypothesis/__init__.py index e69de29..9bb17f2 100644 --- a/hypothesis/__init__.py +++ b/hypothesis/__init__.py @@ -0,0 +1,33 @@ +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())