From f4c4407ebcaf9a0f5642123621d23990758558e6 Mon Sep 17 00:00:00 2001 From: olari Date: Fri, 18 Jun 2021 03:50:32 +0300 Subject: [PATCH] fix parser --- parse.py | 13 ++++++++++++- summary.py | 1 - 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/parse.py b/parse.py index 5d4528a..1f97273 100644 --- a/parse.py +++ b/parse.py @@ -2,7 +2,6 @@ from pathlib import Path from datetime import datetime import re import json -from functools import reduce entry_re = re.compile(r'^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})', re.MULTILINE) @@ -20,9 +19,21 @@ def parse_habits(habits): result[name] = value[1] == 'x' return result +def parse_notifications(notifications): + result = [] + for notification in notifications.splitlines(): + parts = notification.split() + result.append({ + 'source': ' '.join(parts[0:2]).strip('[]'), + 'message': ' '.join(parts[2:]), + }) + return result + + header_modules = { 'godword': parse_godword, 'habits': parse_habits, + 'notifications': parse_notifications, } def parse_header(header): diff --git a/summary.py b/summary.py index 06fac9c..d87b316 100644 --- a/summary.py +++ b/summary.py @@ -1,4 +1,3 @@ -from datetime import datetime import json import sys