simplify provider
This commit is contained in:
parent
de5e90f3fe
commit
0baa2f20cc
2 changed files with 9 additions and 15 deletions
|
@ -4,28 +4,26 @@ from datetime import datetime
|
|||
from pathlib import Path
|
||||
import logging
|
||||
|
||||
import os
|
||||
|
||||
BPATH = "/L/backups/github-events"
|
||||
BPATH = Path("/L/backups/github-events")
|
||||
|
||||
|
||||
def get_logger():
|
||||
return logging.getLogger('github-provider')
|
||||
|
||||
def iter_files():
|
||||
for f in os.listdir(BPATH):
|
||||
if f.endswith('.json'):
|
||||
yield os.path.join(BPATH, f)
|
||||
|
||||
def iter_events():
|
||||
for f in list(sorted(iter_files())):
|
||||
for f in list(sorted(BPATH.glob('*.json'))):
|
||||
yield f
|
||||
|
||||
|
||||
class Event(NamedTuple):
|
||||
dt: datetime
|
||||
summary: str
|
||||
eid: str
|
||||
link: Optional[str]
|
||||
|
||||
|
||||
# TODO split further, title too
|
||||
def _get_summary(e) -> Tuple[str, Optional[str]]:
|
||||
tp = e['type']
|
||||
|
@ -97,3 +95,7 @@ def get_events():
|
|||
eid=d['id'],
|
||||
) for d in events.values()]
|
||||
return sorted(ev, key=lambda e: e.dt)
|
||||
|
||||
|
||||
def test():
|
||||
assert len(get_events()) > 100
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
from github import get_events, get_logger
|
||||
from kython import setup_logzero
|
||||
|
||||
logger = get_logger()
|
||||
setup_logzero(logger)
|
||||
|
||||
for e in get_events():
|
||||
print(e)
|
Loading…
Add table
Reference in a new issue