Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ArtrenH/VPlan_FR
Browse files Browse the repository at this point in the history
  • Loading branch information
OfficialFreak committed Sep 25, 2023
2 parents e19165f + 09b22c0 commit be589cb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
17 changes: 8 additions & 9 deletions backend/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,22 @@ def get_plan_file(self,
"""Return the contents of a plan file from the cache."""
# self._logger.debug(f"get_plan_file({day!r}, {timestamp!r}, {filename!r})")

if newest_before:
if newest_before and not isinstance(timestamp, str):
timestamps = self.get_timestamps(day)
if not isinstance(timestamp, str):
timestamps = [t for t in timestamps if t <= timestamp]
timestamps = [t for t in timestamps if t <= timestamp]

for timestamp in timestamps:
for older_timestamp in timestamps:
try:
return self.get_plan_file(day, timestamp, filename, newest_before=False)
return self.get_plan_file(day, older_timestamp, filename, newest_before=False)
except OSError:
pass
else:
raise FileNotFoundError
else:
path = self.get_plan_path(day, timestamp) / filename

path = self.get_plan_path(day, timestamp) / filename

with open(path, "r", encoding="utf-8") as f:
return f.read()
with open(path, "r", encoding="utf-8") as f:
return f.read()

def store_meta_file(self, content: str, filename: str):
"""Store a meta file in the cache such as "meta.json"."""
Expand Down
3 changes: 0 additions & 3 deletions backend/meta_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ def iterate_daily_extractors(self) -> typing.Generator[DailyMetaExtractor, None,
try:
plan_kl = self.cache.get_plan_file(day, timestamp, "PlanKl.xml")
except FileNotFoundError:
self._logger.warning(
f"Timestamp {timestamp!s} for day {day!s} has no PlanKl.xml file."
)
continue

extractor = DailyMetaExtractor(plan_kl)
Expand Down
4 changes: 2 additions & 2 deletions backend/plan_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class PlanProcessor:
VERSION = "74"
VERSION = "75"

def __init__(self, cache: Cache, school_number: str, *, logger: logging.Logger):
self._logger = logger
Expand Down Expand Up @@ -67,7 +67,7 @@ def compute_plans(self, date: datetime.date, timestamp: datetime.datetime):
self._logger.warning(f"=> Could not find Indiware form plan for date {date!s} and timestamp {timestamp!s}.")
else:
try:
vplan_kl = self.cache.get_plan_file(date, timestamp, "VPlanKl.xml", newest_before=True)
vplan_kl = self.cache.get_plan_file(date, timestamp, "VplanKl.xml", newest_before=True)
except FileNotFoundError:
vplan_kl = None
plan_extractor = PlanExtractor(plan_kl, vplan_kl, self.teachers.abbreviation_by_surname(),
Expand Down
7 changes: 5 additions & 2 deletions backend/vplan_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,16 @@ def periods_to_block_label(periods: list[int]) -> str:


def _parse_periods(period_str: str) -> list[int]:
def period_str_to_int(string: str) -> int:
return int(string.replace("Stunde", "").replace(".", ""))

if not period_str:
return []
elif "-" not in period_str:
return [int(period_str)]
return [period_str_to_int(period_str)]
else:
begin, end = period_str.split("-")
return list(range(int(begin), int(end) + 1))
return list(range(period_str_to_int(begin), period_str_to_int(end) + 1))


def parse_periods(period_str: str) -> list[int]:
Expand Down

0 comments on commit be589cb

Please sign in to comment.