summaryrefslogtreecommitdiff
path: root/jimbrella/routine.py
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-02-19 17:44:03 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-02-19 17:44:03 +0800
commit92ca54b191811df4b6e51f7ef06e453dcf1ac71e (patch)
tree68d1b5951c22c319e5689483facabde088f5c0e4 /jimbrella/routine.py
parentf92064d93b8b6b2e8ee5d8c6579d54f4e331af71 (diff)
Unify tenant and admin loggers
Diffstat (limited to 'jimbrella/routine.py')
-rw-r--r--jimbrella/routine.py40
1 files changed, 15 insertions, 25 deletions
diff --git a/jimbrella/routine.py b/jimbrella/routine.py
index 77d69f2..659fbfa 100644
--- a/jimbrella/routine.py
+++ b/jimbrella/routine.py
@@ -3,7 +3,6 @@ from dateutil.parser import isoparse
import logging
from .umbrellas import Umbrellas
from .jform import JForm
-from .admin_log import AdminLog
from .exceptions import *
from .config import config
from .utils import CST
@@ -40,7 +39,7 @@ def chronological_merge(*sheet_lists) -> list:
return chronicle
-def sync_jform(takeaway: JForm, giveback: JForm, db: Umbrellas, admin: AdminLog):
+def sync_jform(takeaway: JForm, giveback: JForm, db: Umbrellas):
takeaway_unread = takeaway.get_unread()
giveback_unread = giveback.get_unread()
logging.info(
@@ -63,11 +62,6 @@ def sync_jform(takeaway: JForm, giveback: JForm, db: Umbrellas, admin: AdminLog)
sheet["id"],
sheet["phone"],
)
- logging.info(
- tenant_identity
- + " borrowed umbrella #{key} at {date_str}".format(**sheet)
- )
- admin.log("TAKEAWAY", sheet, date=sheet["date"])
except (UmbrellaStatusError, UmbrellaNotFoundError):
logging.warning(
tenant_identity
@@ -77,12 +71,11 @@ def sync_jform(takeaway: JForm, giveback: JForm, db: Umbrellas, admin: AdminLog)
)
elif sheet["jform_name"] == "giveback":
try:
- db.give_back(sheet["key"], sheet["name"], sheet["id"])
+ db.give_back(sheet["key"], sheet["date"], sheet["name"], sheet["id"])
logging.info(
tenant_identity
+ " returned umbrella #{key} at {date_str}".format(**sheet)
)
- admin.log("GIVEBACK", sheet, date=sheet["date"])
except (UmbrellaStatusError, UmbrellaNotFoundError):
logging.warning(
tenant_identity
@@ -99,7 +92,7 @@ def sync_jform(takeaway: JForm, giveback: JForm, db: Umbrellas, admin: AdminLog)
)
-def process_overdue(db: Umbrellas, admin: AdminLog):
+def process_overdue(db: Umbrellas):
"""mark and log umbrellas that were not, but just became overdue"""
umbrellas = db.read()
now = datetime.now().astimezone(CST)
@@ -120,22 +113,19 @@ def process_overdue(db: Umbrellas, admin: AdminLog):
**umb
)
)
- admin.log(
- "OVERDUE",
- {
- "key": umb["id"],
- "name": umb["tenant_name"],
- "phone": umb["tenant_phone"],
- "id": umb["tenant_id"],
- "email": "",
- },
- )
if __name__ == "__main__":
- takeaway = JForm("takeaway", config.get("jform", "takeaway_url"), config.get("jform", "bookmark_dir"))
- giveback = JForm("giveback", config.get("jform", "giveback_url"), config.get("jform", "bookmark_dir"))
+ takeaway = JForm(
+ "takeaway",
+ config.get("jform", "takeaway_url"),
+ config.get("jform", "bookmark_dir"),
+ )
+ giveback = JForm(
+ "giveback",
+ config.get("jform", "giveback_url"),
+ config.get("jform", "bookmark_dir"),
+ )
db = Umbrellas(config.get("general", "db_path"))
- admin_log = AdminLog(config.get("logging", "admin_log_path"))
- sync_jform(takeaway, giveback, db, admin_log)
- process_overdue(db, admin_log)
+ sync_jform(takeaway, giveback, db)
+ process_overdue(db)