From ffe6c14c744eec780c59b45383a4382ec56c5f7c Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sat, 28 Sep 2019 18:53:05 +0100 Subject: [PATCH] add body for github events --- my/coding/github/__init__.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/my/coding/github/__init__.py b/my/coding/github/__init__.py index aa58211..1c41858 100644 --- a/my/coding/github/__init__.py +++ b/my/coding/github/__init__.py @@ -25,6 +25,7 @@ class Event(NamedTuple): summary: str eid: str link: Optional[str] + body: Optional[str]=None # TODO split further, title too @@ -80,19 +81,22 @@ def get_model(): return model -def get_events(): - # from kython import setup_logzero - # import logging - # setup_logzero(ghexport().get_logger(), level=logging.INFO) +def iter_events(): model = get_model() - ev = [Event( - dt=pytz.utc.localize(datetime.strptime(d['created_at'], '%Y-%m-%dT%H:%M:%SZ')), - summary=_get_summary(d)[0], - link=_get_summary(d)[1], - eid=d['id'], - ) for d in model.events()] - return sorted(ev, key=lambda e: e.dt) + for d in model.events(): + summary, link = _get_summary(d) + body = d.get('payload', {}).get('comment', {}).get('body') + yield Event( + # TODO isoformat? + dt=pytz.utc.localize(datetime.strptime(d['created_at'], '%Y-%m-%dT%H:%M:%SZ')), + summary=summary, + link=link, + eid=d['id'], + body=body, + ) +def get_events(): + return sorted(iter_events(), key=lambda e: e.dt) # TODO mm. ok, not much point in deserializing as github.Event as it's basically a fancy dict wrapper? # from github.Event import Event as GEvent # type: ignore