aboutsummaryrefslogtreecommitdiff
path: root/sjdbmk/__main__.py
diff options
context:
space:
mode:
Diffstat (limited to 'sjdbmk/__main__.py')
-rw-r--r--sjdbmk/__main__.py90
1 files changed, 90 insertions, 0 deletions
diff --git a/sjdbmk/__main__.py b/sjdbmk/__main__.py
new file mode 100644
index 0000000..64e9d0f
--- /dev/null
+++ b/sjdbmk/__main__.py
@@ -0,0 +1,90 @@
+import argparse
+import datetime
+import logging
+import os
+import zoneinfo
+from configparser import ConfigParser
+
+from .const import *
+
+
+logger = logging.getLogger(__name__)
+
+
+def main() -> None:
+ logging.basicConfig(level=logging.INFO)
+
+ parser = argparse.ArgumentParser(
+ prog="sjdbmk",
+ description="Songjiang Daily Bulletin Build System",
+ )
+ parser.add_argument(
+ "--config",
+ default="config.ini", # TODO
+ help="path to the configuration file",
+ )
+ parser.add_argument(
+ "--rebuild",
+ action="store_true",
+ default=False,
+ help="rebuild from scratch",
+ )
+ parser.add_argument(
+ "--date",
+ default="",
+ help="build for date",
+ )
+ args = parser.parse_args()
+
+ config = ConfigParser()
+ config.read(args.config)
+
+ tzinfo = zoneinfo.ZoneInfo(config["general"]["timezone"])
+ if args.date:
+ datetime_target_naive = datetime.datetime.strptime(args.date, "%Y-%m-%d")
+ datetime_target = datetime_target_naive.replace(tzinfo=tzinfo)
+ else:
+ datetime_current_aware = datetime.datetime.now(tz=tzinfo)
+ datetime_target = datetime_current_aware + datetime.timedelta(days=((-datetime_current_aware.weekday()) % 7))
+
+ logger.info("Building for %s" % datetime_target.strftime("%Y-%m-%d %Z"))
+
+ build_path = config["general"]["build_path"]
+ os.chdir(build_path)
+
+ the_week_ahead_url = config["the_week_ahead"]["file_url"]
+ the_week_ahead_community_time_page_number = int(config["the_week_ahead"]["community_time_page_number"])
+ the_week_ahead_aod_page_number = int(config["the_week_ahead"]["aod_page_number"])
+
+ weekly_menu_query_string = config["weekly_menu"]["query_string"]
+ weekly_menu_sender = config["weekly_menu"]["sender"]
+ weekly_menu_subject_regex = config["weekly_menu"]["subject_regex"]
+ weekly_menu_subject_regex_four_groups_raw = config["weekly_menu"]["subject_regex_four_groups"].split(" ")
+ weekly_menu_subject_regex_four_groups = tuple([int(z) for z in weekly_menu_subject_regex_four_groups_raw])
+ assert len(weekly_menu_subject_regex_four_groups) == 4
+ del weekly_menu_subject_regex_four_groups_raw
+
+ graph_client_id = config["credentials"]["client_id"]
+ graph_authority = config["credentials"]["authority"]
+ graph_username = config["credentials"]["username"]
+ graph_password = config["credentials"]["password"]
+ graph_scopes = config["credentials"]["scope"].split(" ")
+
+ calendar_address = config["calendar"]["address"]
+
+ generate(
+ datetime_target=datetime_target,
+ the_week_ahead_url=the_week_ahead_url,
+ the_week_ahead_community_time_page_number=the_week_ahead_community_time_page_number,
+ the_week_ahead_aod_page_number=the_week_ahead_aod_page_number,
+ weekly_menu_query_string=weekly_menu_query_string,
+ weekly_menu_sender=weekly_menu_sender,
+ weekly_menu_subject_regex=weekly_menu_subject_regex,
+ weekly_menu_subject_regex_four_groups=weekly_menu_subject_regex_four_groups,
+ graph_client_id=graph_client_id,
+ graph_authority=graph_authority,
+ graph_username=graph_username,
+ graph_password=graph_password,
+ graph_scopes=graph_scopes,
+ calendar_address=calendar_address,
+ )