fix parser
This commit is contained in:
13
parse.py
13
parse.py
@@ -2,7 +2,6 @@ from pathlib import Path
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import re
|
import re
|
||||||
import json
|
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)
|
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'
|
result[name] = value[1] == 'x'
|
||||||
return result
|
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 = {
|
header_modules = {
|
||||||
'godword': parse_godword,
|
'godword': parse_godword,
|
||||||
'habits': parse_habits,
|
'habits': parse_habits,
|
||||||
|
'notifications': parse_notifications,
|
||||||
}
|
}
|
||||||
|
|
||||||
def parse_header(header):
|
def parse_header(header):
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
from datetime import datetime
|
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user