Skip to content

Commit

Permalink
Merge pull request #105 from filips123/eclassroom-updater-parameters
Browse files Browse the repository at this point in the history
Add parameters to eclassroom updater
  • Loading branch information
filips123 authored Sep 11, 2024
2 parents 8c64ed7 + d45960b commit d06a9e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 8 additions & 3 deletions API/gimvicurnik/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,24 @@ def update_timetable_command() -> None:
updater.update()


# fmt: off
@click.command("update-eclassroom", help="Update the e-classroom data.")
@click.option("--parse-substitutions", "-p", help="Parse substitutions.", is_flag=True)
@click.option("--parse-substitutions/--no-parse-substitutions", "-s/-no-s", help="Parse substitutions.", default=False)
@click.option("--parse-lunch-schedules/--no-parse-lunch-schedules", "-l/-no-l", help="Parse lunch schedules.", default=True)
@click.option("--extract-circulars/--no-extract-circulars", "-c/-no-c", help="Extract circulars.", default=True)
@with_transaction(name="update-eclassroom", op="command")
def update_eclassroom_command(parse_substitutions: bool = False) -> None:
def update_eclassroom_command(parse_substitutions: bool, parse_lunch_schedules: bool, extract_circulars: bool) -> None:
"""Update data from the e-classroom."""

logging.getLogger(__name__).info("Updating the e-classroom data")

with SessionFactory.begin() as session:
gimvicurnik: GimVicUrnik = current_app.config["GIMVICURNIK"]
updater = EClassroomUpdater(gimvicurnik.config.sources.eclassroom, session, parse_substitutions, True)
updater = EClassroomUpdater(gimvicurnik.config.sources.eclassroom, session, parse_substitutions, parse_lunch_schedules, extract_circulars)
updater.update()

# fmt: on


@click.command("update-menu", help="Update the menu data.")
@with_transaction(name="update-menu", op="command")
Expand Down
6 changes: 4 additions & 2 deletions API/gimvicurnik/updaters/eclassroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ def __init__(
session: Session,
parse_substitutions: bool,
parse_lunch_schedules: bool,
extract_circulars: bool,
) -> None:
self.logger = logging.getLogger(__name__)
self.config = config
self.session = session

self.parse_substitutions = parse_substitutions
self.parse_lunch_schedules = parse_lunch_schedules
self.extract_circulars = extract_circulars

super().__init__()

Expand Down Expand Up @@ -308,9 +310,9 @@ def parse_document( # type: ignore[override]
def document_needs_extraction(self, document: DocumentInfo) -> bool:
"""Return whether the document content needs to be extracted."""

# Only DOCX documents (circulars) can have content extracted
# Only DOCX documents (circulars and some other) can have content extracted
if document.extension == "docx":
return True
return self.extract_circulars

return False

Expand Down

0 comments on commit d06a9e0

Please sign in to comment.