summaryrefslogtreecommitdiff
path: root/jimbrella
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2021-10-31 14:47:28 +0800
committerFrederick Yin <fkfd@fkfd.me>2021-10-31 14:47:28 +0800
commit43ff7feecb63037739306f1a80944a1abfb669ce (patch)
tree03d5fecc0a13e13a0031c2d3224ccdda7bc018a1 /jimbrella
parentfb6b5b74df451f943190f6c757e6f9de04cce7ab (diff)
AdminLog keeps log and skips when an entry cannot be read
Diffstat (limited to 'jimbrella')
-rw-r--r--jimbrella/admin_log.py61
1 files changed, 35 insertions, 26 deletions
diff --git a/jimbrella/admin_log.py b/jimbrella/admin_log.py
index 8308336..8b5bb09 100644
--- a/jimbrella/admin_log.py
+++ b/jimbrella/admin_log.py
@@ -1,5 +1,6 @@
import csv
import os
+import logging
from datetime import datetime
from .lockfile import Lockfile
from .utils import human_datetime
@@ -50,33 +51,41 @@ class AdminLog:
with open(self.path) as f:
reader = csv.reader(f)
logs = []
- for row in reader:
- event = row[0]
- entry = {
- "event": event,
- "date": datetime.fromisoformat(row[1]),
- "note": row[-1],
- }
- info = {}
- if event in ("TAKEAWAY", "GIVEBACK", "OVERDUE"):
- info = {
- "key": int(row[2]),
- "name": row[3],
- "id": row[4],
- "phone": row[5],
- "email": row[6],
+ for ln, row in enumerate(reader):
+ try:
+ event = row[0]
+ entry = {
+ "event": event,
+ "date": datetime.fromisoformat(row[1]),
+ "note": row[-1],
}
- elif event == "ADMIN_MODIFY_DB":
- info = {
- "admin_name": row[2],
- "serial": int(row[3]),
- "column": row[4],
- "past_value": row[5],
- "new_value": row[6],
- }
-
- entry.update(info)
- logs.append(entry)
+ info = {}
+ if event in ("TAKEAWAY", "GIVEBACK", "OVERDUE"):
+ info = {
+ "key": int(row[2]),
+ "name": row[3],
+ "id": row[4],
+ "phone": row[5],
+ "email": row[6],
+ }
+ elif event == "ADMIN_MODIFY_DB":
+ info = {
+ "admin_name": row[2],
+ "serial": int(row[3]),
+ "column": row[4],
+ "past_value": row[5],
+ "new_value": row[6],
+ }
+ else:
+ logging.warning(
+ "%s:%d is not a recognized event. Skip.", self.path, ln
+ )
+ continue
+
+ entry.update(info)
+ logs.append(entry)
+ except Exception:
+ logging.warning("%s:%d cannot be read. Skip.", self.path, ln)
f.close()
return logs