aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sjdbmk/cal.py3
-rw-r--r--sjdbmk/common.py5
-rw-r--r--sjdbmk/menu.py5
-rw-r--r--[-rwxr-xr-x]sjdbmk/pack.py0
-rw-r--r--sjdbmk/twa.py6
-rw-r--r--sjdbmk/weekly.py2
6 files changed, 18 insertions, 3 deletions
diff --git a/sjdbmk/cal.py b/sjdbmk/cal.py
index 0d57711..eccedc3 100644
--- a/sjdbmk/cal.py
+++ b/sjdbmk/cal.py
@@ -17,11 +17,12 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
-from typing import Any
+from typing import Any
import datetime
import requests
+
def calfetch(token: str, calendar_address: str, datetime_target: datetime.datetime) -> Any:
calendar_response = requests.get(
"https://graph.microsoft.com/v1.0/users/%s/calendar/calendarView" % calendar_address,
diff --git a/sjdbmk/common.py b/sjdbmk/common.py
index d65b3d5..1d315cc 100644
--- a/sjdbmk/common.py
+++ b/sjdbmk/common.py
@@ -26,6 +26,7 @@ import shutil
import requests
import msal # type: ignore
+
def acquire_token(
graph_client_id: str,
graph_authority: str,
@@ -44,6 +45,7 @@ def acquire_token(
return result["access_token"]
raise ValueError("Authentication error in password login")
+
def search_mail(token: str, query_string: str) -> list[dict[str, Any]]:
hits = requests.post(
"https://graph.microsoft.com/v1.0/search/query",
@@ -69,6 +71,7 @@ def search_mail(token: str, query_string: str) -> list[dict[str, Any]]:
assert isinstance(hits[0], dict)
return hits
+
def encode_sharing_url(url: str) -> str:
return "u!" + base64.urlsafe_b64encode(url.encode("utf-8")).decode("ascii").rstrip("=")
@@ -94,6 +97,7 @@ def download_share_url(token: str, url: str, local_filename: str, chunk_size: in
shutil.copyfileobj(r.raw, fd)
fd.flush()
+
def filter_mail_results_by_sender(original: Iterable[dict[str, Any]], sender: str) -> Iterator[dict[str, Any]]:
for hit in original:
if hit["resource"]["sender"]["emailAddress"]["address"].lower() == sender.lower():
@@ -112,5 +116,6 @@ def filter_mail_results_by_subject_regex_groups(
if matched:
yield (hit, [matched.group(group) for group in subject_regex_groups])
+
class DailyBulletinError(Exception):
pass
diff --git a/sjdbmk/menu.py b/sjdbmk/menu.py
index 7c173ab..f6a26a5 100644
--- a/sjdbmk/menu.py
+++ b/sjdbmk/menu.py
@@ -27,10 +27,11 @@ import os
import openpyxl
-import common
+from . import common
logger = logging.getLogger(__name__)
+
def menu_item_fix(s: str) -> Optional[str]:
if not s:
return None
@@ -137,6 +138,7 @@ def parse_menus(datetime_target: datetime.datetime) -> dict[str, dict[str, dict[
return final
+
def download_menu(
token: str,
datetime_target: datetime.datetime,
@@ -187,6 +189,7 @@ def download_menu(
else:
raise ValueError("No proper attachment found in email")
+
def download_or_report_menu(token: str, datetime_target: datetime.datetime, weekly_menu_query_string: str, weekly_menu_sender: str, weekly_menu_subject_regex: str, weekly_menu_subject_regex_four_groups: tuple[int, int, int, int]) -> None:
menu_filename = "menu-%s.xlsx" % datetime_target.strftime("%Y%m%d")
if not (os.path.isfile(menu_filename)):
diff --git a/sjdbmk/pack.py b/sjdbmk/pack.py
index 192cd09..192cd09 100755..100644
--- a/sjdbmk/pack.py
+++ b/sjdbmk/pack.py
diff --git a/sjdbmk/twa.py b/sjdbmk/twa.py
index 34f00a5..371a01b 100644
--- a/sjdbmk/twa.py
+++ b/sjdbmk/twa.py
@@ -23,10 +23,11 @@ import os
import pptx
-import common
+from . import common
logger = logging.getLogger(__name__)
+
def download_or_report_the_week_ahead(token: str, datetime_target: datetime.datetime, the_week_ahead_url: str) -> None:
the_week_ahead_filename = "the_week_ahead-%s.pptx" % datetime_target.strftime("%Y%m%d")
if not os.path.isfile(the_week_ahead_filename):
@@ -36,6 +37,7 @@ def download_or_report_the_week_ahead(token: str, datetime_target: datetime.date
else:
logger.info("The Week Ahead already exists at %s" % the_week_ahead_filename)
+
def parse_the_week_ahead(datetime_target: datetime.datetime, the_week_ahead_community_time_page_number: int, the_week_ahead_aod_page_number: int) -> tuple[list[list[str]], list[str]]:
logger.info("Parsing The Week Ahead")
the_week_ahead_filename = "the_week_ahead-%s.pptx" % datetime_target.strftime("%Y%m%d")
@@ -47,6 +49,7 @@ def parse_the_week_ahead(datetime_target: datetime.datetime, the_week_ahead_comm
aods = extract_aods(the_week_ahead_presentation, the_week_ahead_aod_page_number)
return community_time, aods
+
def extract_community_time(prs: pptx.presentation.Presentation, community_time_page_number: int) -> list[list[str]]:
slide = prs.slides[community_time_page_number]
for shape in slide.shapes:
@@ -86,6 +89,7 @@ def extract_community_time(prs: pptx.presentation.Presentation, community_time_p
return [x[1:] for x in res[1:]]
+
def extract_aods(prs: pptx.presentation.Presentation, aod_page_number: int) -> list[str]:
slide = prs.slides[aod_page_number]
aods = ["", "", "", ""]
diff --git a/sjdbmk/weekly.py b/sjdbmk/weekly.py
index 3006582..aef2f39 100644
--- a/sjdbmk/weekly.py
+++ b/sjdbmk/weekly.py
@@ -51,6 +51,7 @@ from . import common, twa, menu
logger = logging.getLogger(__name__)
+
def generate(
datetime_target: datetime.datetime, # expected to be local time
the_week_ahead_url: str,
@@ -91,6 +92,7 @@ def generate(
json.dump(final_data, fd, ensure_ascii=False, indent="\t")
return output_filename
+
def main() -> None:
logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser(description="Weekly script for the Daily Bulletin")