summaryrefslogtreecommitdiff
path: root/jimbrella
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2021-10-22 22:04:40 +0800
committerFrederick Yin <fkfd@fkfd.me>2021-10-22 22:04:40 +0800
commitec7ff623a83146d1a814fbe30b922500a1bfe711 (patch)
tree9ce9a18c7ec5f6519226f5d17c120db7e18ca8a6 /jimbrella
parentec890f80cc0491b8109eb9ae8d4c27c721900156 (diff)
JForm: fixes, comments, datatype, return value
Diffstat (limited to 'jimbrella')
-rw-r--r--jimbrella/jform.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/jimbrella/jform.py b/jimbrella/jform.py
index cd48c3e..de2c508 100644
--- a/jimbrella/jform.py
+++ b/jimbrella/jform.py
@@ -1,6 +1,7 @@
import requests
import json
from pathlib import Path
+from datetime import datetime
class JForm:
@@ -26,7 +27,7 @@ class JForm:
"""
self._name = name
self.url = url
- self._bookmark_fp = Path(bookmark_dir).join(f"{name}.bookmark")
+ self._bookmark_fp = Path(bookmark_dir) / (f"{name}.bookmark")
def _get(self, page=1) -> dict:
"""Internal method to HTTP GET the API in JSON format."""
@@ -52,6 +53,9 @@ class JForm:
f.close()
return int(bookmark)
except FileNotFoundError:
+ # create file
+ with open(self._bookmark_fp, "x") as f:
+ f.close()
return 0
def _write_bookmark(self, bookmark: int) -> None:
@@ -66,7 +70,15 @@ class JForm:
f.close()
def get_unread(self) -> list:
- """Get unread answers to required fields as a list of dicts, most recent last."""
+ """Get unread answers to required fields as a list of dicts, most recent last.
+
+ Keys of a dict in the list:
+ - name: (string) Tenant's name.
+ - id: (uint) Tenant's student/faculty ID.
+ - phone: (string) Tenant's phone number.
+ - key: (uint) Number of key to umbrella.
+ - date: (datetime.datetime) When the jForm answer sheet was submitted.
+ """
bookmark = self._read_bookmark()
unread = []
latest_id = 0
@@ -101,10 +113,12 @@ class JForm:
ans = sheet["answers"]
unread.append(
{
+ "jform_name": self._name,
"name": ans[0]["answer"],
"id": ans[1]["answer"],
"phone": ans[2]["answer"],
- "key": ans[3]["answer"],
+ "key": int(ans[3]["answer"]),
+ "date": datetime.fromisoformat(sheet["submitted_at"]),
}
)
page += 1