aboutsummaryrefslogtreecommitdiff
path: root/sjdbmk
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--[-rwxr-xr-x]sjdbmk/daily.py (renamed from daily.py)0
-rw-r--r--[-rwxr-xr-x]sjdbmk/grant.py (renamed from grant.py)0
-rw-r--r--[-rwxr-xr-x]sjdbmk/inspire_approve.py (renamed from inspire_approve.py)0
-rw-r--r--[-rwxr-xr-x]sjdbmk/inspire_dl.py (renamed from inspire_dl.py)0
-rw-r--r--[-rwxr-xr-x]sjdbmk/legacy_wikipedia.py (renamed from legacy_wikipedia.py)0
-rw-r--r--sjdbmk/menuparser.py (renamed from menuparser.py)5
-rw-r--r--[-rwxr-xr-x]sjdbmk/msal_skeleton.py (renamed from msal_skeleton.py)0
-rw-r--r--[-rwxr-xr-x]sjdbmk/pack.py (renamed from pack.py)0
-rw-r--r--[-rwxr-xr-x]sjdbmk/sendmail.py (renamed from sendmail.py)17
-rw-r--r--sjdbmk/sendmail2.py (renamed from sendmail2.py)0
-rw-r--r--[-rwxr-xr-x]sjdbmk/serve.py (renamed from serve.py)0
-rw-r--r--[-rwxr-xr-x]sjdbmk/weekly.py (renamed from weekly.py)19
12 files changed, 18 insertions, 23 deletions
diff --git a/daily.py b/sjdbmk/daily.py
index ce21bce..ce21bce 100755..100644
--- a/daily.py
+++ b/sjdbmk/daily.py
diff --git a/grant.py b/sjdbmk/grant.py
index d55d9d6..d55d9d6 100755..100644
--- a/grant.py
+++ b/sjdbmk/grant.py
diff --git a/inspire_approve.py b/sjdbmk/inspire_approve.py
index 98d202c..98d202c 100755..100644
--- a/inspire_approve.py
+++ b/sjdbmk/inspire_approve.py
diff --git a/inspire_dl.py b/sjdbmk/inspire_dl.py
index 631ea44..631ea44 100755..100644
--- a/inspire_dl.py
+++ b/sjdbmk/inspire_dl.py
diff --git a/legacy_wikipedia.py b/sjdbmk/legacy_wikipedia.py
index c2f60a1..c2f60a1 100755..100644
--- a/legacy_wikipedia.py
+++ b/sjdbmk/legacy_wikipedia.py
diff --git a/menuparser.py b/sjdbmk/menuparser.py
index 71b7f6f..7413ff0 100644
--- a/menuparser.py
+++ b/sjdbmk/menuparser.py
@@ -17,10 +17,11 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
-import openpyxl
from typing import Optional, Any
+import openpyxl
+
def menu_item_fix(s: str) -> Optional[str]:
if not s:
@@ -88,7 +89,7 @@ def parse_menus(filename: str) -> dict[str, dict[str, dict[str, list[str]]]]:
row = rows[i]
if not isinstance(row[1].value, str):
continue
- elif "BREAKFAST" in row[1].value:
+ if "BREAKFAST" in row[1].value:
final["Breakfast"] = parse_meal_table(
rows,
i,
diff --git a/msal_skeleton.py b/sjdbmk/msal_skeleton.py
index 3261341..3261341 100755..100644
--- a/msal_skeleton.py
+++ b/sjdbmk/msal_skeleton.py
diff --git a/pack.py b/sjdbmk/pack.py
index 902e256..902e256 100755..100644
--- a/pack.py
+++ b/sjdbmk/pack.py
diff --git a/sendmail.py b/sjdbmk/sendmail.py
index c118c77..ddd6f32 100755..100644
--- a/sendmail.py
+++ b/sjdbmk/sendmail.py
@@ -30,6 +30,11 @@ import requests
import msal # type: ignore
+def open_and_readlines(filename: str) -> list[str]:
+ with open(filename, "r") as fd:
+ return fd.readlines()
+
+
def acquire_token(app: msal.PublicClientApplication, config: ConfigParser) -> str:
result = app.acquire_token_by_username_password(
config["credentials"]["username"],
@@ -96,9 +101,9 @@ def sendmail(
try:
msgid = response["id"]
- except KeyError:
+ except KeyError as exc:
pprint(response)
- raise ValueError("Unable to add email to drafts")
+ raise ValueError("Unable to add email to drafts") from exc
assert isinstance(msgid, str)
@@ -169,7 +174,7 @@ def main() -> None:
cc=config["sendmail"]["cc_1"].split(" "),
bcc=[
w.strip()
- for w in open(config["sendmail"]["bcc_1_file"], "r").readlines()
+ for w in open_and_readlines(config["sendmail"]["bcc_1_file"])
if w.strip()
],
when=date.replace(
@@ -193,7 +198,7 @@ def main() -> None:
cc=config["sendmail"]["cc_2"].split(" "),
bcc=[
w.strip()
- for w in open(config["sendmail"]["bcc_2_file"], "r").readlines()
+ for w in open_and_readlines(config["sendmail"]["bcc_2_file"])
if w.strip()
],
when=date.replace(
@@ -220,7 +225,7 @@ def main() -> None:
cc=config["sendmail"]["cc_1"].split(" "),
bcc=[
w.strip()
- for w in open(config["sendmail"]["bcc_1_file"], "r").readlines()
+ for w in open_and_readlines(config["sendmail"]["bcc_1_file"])
if w.strip()
],
when=date.replace(
@@ -247,7 +252,7 @@ def main() -> None:
cc=config["sendmail"]["cc_2"].split(" "),
bcc=[
w.strip()
- for w in open(config["sendmail"]["bcc_2_file"], "r").readlines()
+ for w in open_and_readlines(config["sendmail"]["bcc_2_file"])
if w.strip()
],
when=date.replace(
diff --git a/sendmail2.py b/sjdbmk/sendmail2.py
index 6cfda8c..6cfda8c 100644
--- a/sendmail2.py
+++ b/sjdbmk/sendmail2.py
diff --git a/serve.py b/sjdbmk/serve.py
index 492e443..492e443 100755..100644
--- a/serve.py
+++ b/sjdbmk/serve.py
diff --git a/weekly.py b/sjdbmk/weekly.py
index 3923aa8..9c0a0c9 100755..100644
--- a/weekly.py
+++ b/sjdbmk/weekly.py
@@ -55,18 +55,6 @@ import menuparser
logger = logging.getLogger(__name__)
-class MealTableShapeError(ValueError):
- pass
-
-
-def zero_list(lt: list[Any]) -> list[Any]:
- return [(zero_list(i) if (isinstance(i, list)) else "") for i in lt]
-
-
-def equal_shapes(a: list[Any], b: list[Any]) -> bool:
- return zero_list(a) == zero_list(b)
-
-
def generate(
datetime_target: datetime.datetime, # expected to be local time
the_week_ahead_url: str,
@@ -130,7 +118,7 @@ def generate(
logger.info("The Week Ahead already exists at %s" % the_week_ahead_filename)
menu_filename = "menu-%s.xlsx" % datetime_target.strftime("%Y%m%d")
- if not (os.path.isfile(menu_filename)):
+ if not os.path.isfile(menu_filename):
logger.info("Menu not found, downloading")
download_menu(
token,
@@ -489,8 +477,8 @@ def download_menu(
matched_groups[0], "%b" # issues here are probably locales
).month
subject_1st_day = int(matched_groups[1])
- except ValueError:
- raise ValueError(hit["resource"]["subject"], matched_groups[0])
+ except ValueError as exc:
+ raise ValueError(hit["resource"]["subject"], matched_groups[0]) from exc
if (
subject_1st_month == datetime_target.month
and subject_1st_day == datetime_target.day
@@ -519,6 +507,7 @@ def download_menu(
with open(menu_filename, "wb") as w:
w.write(pb)
+ break
else:
raise ValueError("No proper attachment found in email")