Skip to content

Commit

Permalink
feat: prepare for sum24
Browse files Browse the repository at this point in the history
  • Loading branch information
dantetemplar committed Jun 1, 2024
1 parent 5f850a1 commit 8ccce4e
Show file tree
Hide file tree
Showing 118 changed files with 14,506 additions and 1,739 deletions.
1,794 changes: 712 additions & 1,082 deletions poetry.lock

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ authors = ["Ruslan Bel'kov <[email protected]>"]
readme = "schedule/README.md"

[tool.poetry.dependencies]
python = "~3.11"
google-api-python-client = "^2.73.0"
google-auth-httplib2 = "^0.1.0"
google-auth-oauthlib = "^1.0.0"
python = "~3.12"
google-api-python-client = "^2.131.0"
google-auth-httplib2 = "^0.2.0"
google-auth-oauthlib = "^1.2.0"
pandas = {extras = ["openpyxl"], version = "^2.0.3"}
pydantic = "^1.10"
icalendar = "^5.0.4"
google = {extras = ["auth"], version = "^3.0.0"}
aiohttp = "^3.8.4"
openpyxl = "^3.1.2"
python-dotenv = "^1.0.1"

[tool.poetry.group.dev.dependencies]
black = "^23.3.0"
ruff = "^0.4.7"

2 changes: 2 additions & 0 deletions schedule/.example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PARSER_AUTH_KEY=...very_long_string...
INNOHASSLE_API_URL=https://api.innohassle.ru/events/v0
13 changes: 6 additions & 7 deletions schedule/cleaning/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

from schedule.cleaning.config import cleaning_config as config
from schedule.cleaning.parser import CleaningParser, CleaningEvent, LinenChangeEvent
from schedule.innohassle import Output, InNoHassleEventsClient, update_inh_event_groups
from schedule.models import PredefinedEventGroup, PredefinedTag
from schedule.innohassle import Output, InNoHassleEventsClient, update_inh_event_groups, CreateTag, CreateEventGroup
from schedule.processors.regex import sluggify
from schedule.utils import get_base_calendar

Expand All @@ -25,13 +24,13 @@

cleaning_events = sorted(cleaning_events, key=lambda x: x.location)

cleaning_tag = PredefinedTag(
cleaning_tag = CreateTag(
alias="cleaning",
name="Cleaning",
type="category",
)

cleaning_cleaning_tag = PredefinedTag(
cleaning_cleaning_tag = CreateTag(
alias="room-cleaning",
name="Room Cleaning",
type="cleaning",
Expand All @@ -55,7 +54,7 @@
file_path = directory / filename

event_groups.append(
PredefinedEventGroup(
CreateEventGroup(
alias=group_alias,
name=f"Cleaning: {location}",
description=f"Cleaning schedule for {location}",
Expand All @@ -71,7 +70,7 @@

logging.info(f"Linen change events: {len(linen_change_events)}")

linen_change_tag = PredefinedTag(
linen_change_tag = CreateTag(
alias="linen-change",
name="Linen Change",
type="cleaning",
Expand All @@ -98,7 +97,7 @@
file_path = directory / filename

event_groups.append(
PredefinedEventGroup(
CreateEventGroup(
alias=group_alias,
name=f"Linen Change: {location}",
description=f"Linen change schedule for {location}",
Expand Down
1 change: 0 additions & 1 deletion schedule/cleaning/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"INNOHASSLE_API_URL": "https://api.innohassle.ru/events/v0",
"SAVE_ICS_PATH": "cleaning",
"SAVE_JSON_PATH": "cleaning.json",
"START_DATE": "2024-01-01",
Expand Down
14 changes: 13 additions & 1 deletion schedule/config_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
from pathlib import Path
from typing import Optional

from dotenv import load_dotenv
from pydantic import BaseModel, validator, SecretStr

from schedule.utils import get_project_root

load_dotenv()

PROJECT_ROOT = get_project_root()


Expand Down Expand Up @@ -111,11 +114,20 @@ def create_dir(cls, v, values):
return v

@validator("PARSER_AUTH_KEY", pre=True, always=True)
def from_env(cls, v):
def parser_key_from_env(cls, v):
"""Get PARSER_AUTH_KEY from environment variable"""
if v is None:
from os import environ
v = environ.get("PARSER_AUTH_KEY")

return v

@validator("INNOHASSLE_API_URL", pre=True, always=True)
def api_url_from_env(cls, v):
"""Get INNOHASSLE_API_URL from environment variable"""
if v is None:
from os import environ
v = environ.get("INNOHASSLE_API_URL")
return v


Expand Down
24 changes: 10 additions & 14 deletions schedule/core_courses/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
from schedule.innohassle import (
InNoHassleEventsClient,
Output,
update_inh_event_groups,
update_inh_event_groups, CreateTag, CreateEventGroup,
)
from schedule.models import PredefinedEventGroup, PredefinedTag
from schedule.processors.regex import sluggify
from schedule.utils import get_base_calendar

Expand Down Expand Up @@ -90,22 +89,20 @@ def get_dataframes_pipeline() -> dict[str, pd.DataFrame]:
# -------- Append generated events to events list --------
events.extend(chain.from_iterable(event_generators))

predefined_event_groups: list[PredefinedEventGroup] = []
predefined_event_groups: list[CreateEventGroup] = []

events.sort(key=lambda x: (x.course, x.group))
directory = config.SAVE_ICS_PATH
academic_tag = PredefinedTag(
academic_tag = CreateTag(
alias="core-courses",
name="Core courses",
type="category",
)
semester_tag = PredefinedTag(
semester_tag = CreateTag(
alias=config.SEMESTER_TAG.alias,
name=config.SEMESTER_TAG.name,
type=config.SEMESTER_TAG.type,
)
academic_tag_reference = academic_tag.reference
semester_tag_reference = semester_tag.reference

logging.info("Writing JSON and iCalendars files...")
logging.info(f"> Mount point: {config.MOUNT_POINT}")
Expand All @@ -114,12 +111,11 @@ def get_dataframes_pipeline() -> dict[str, pd.DataFrame]:
courses = set(event.course for event in events)
for (course, group), group_events in groupby(events, lambda x: (x.course, x.group)):
course_slug = sluggify(course)
course_tag = PredefinedTag(
course_tag = CreateTag(
alias=course_slug,
name=course,
type="core-courses",
)
course_tag_reference = course_tag.reference
tags.append(course_tag)

group_calendar = get_base_calendar()
Expand All @@ -139,7 +135,7 @@ def get_dataframes_pipeline() -> dict[str, pd.DataFrame]:
group_calendar.add("x-wr-total-vevents", str(cnt))

group_slug = sluggify(group)
group_alias = f"{semester_tag_reference.alias}-{group_slug}"
group_alias = f"{semester_tag.alias}-{group_slug}"
course_path = directory / course_slug
course_path.mkdir(parents=True, exist_ok=True)
file_name = f"{group_slug}.ics"
Expand All @@ -153,15 +149,15 @@ def get_dataframes_pipeline() -> dict[str, pd.DataFrame]:
f.write(content)

predefined_event_groups.append(
PredefinedEventGroup(
CreateEventGroup(
alias=group_alias,
name=group,
description=f"Core courses schedule for '{group}'",
path=file_path.relative_to(config.MOUNT_POINT).as_posix(),
tags=[
academic_tag_reference,
semester_tag_reference,
course_tag_reference,
academic_tag,
semester_tag,
course_tag,
],
)
)
Expand Down
21 changes: 9 additions & 12 deletions schedule/core_courses/config.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
{
"INNOHASSLE_API_URL": "https://api.innohassle.ru/events/v0",
"SPREADSHEET_ID": "1cb4rfmYgBEk_qmylyA-utX8aDUpmnLAEX-cqFgPaTes",
"SEMESTER_TAG": {
"alias": "s24",
"name": "Spring 2024",
"alias": "sum24",
"name": "Summer 2024",
"type": "semester"
},
"TARGETS": [
{
"sheet_name": "1st block common",
"range": "A1:AU116",
"start_date": "2024-01-22",
"end_date": "2024-05-25",
"sheet_name": "SUMMER 2024",
"range": "A1:AC116",
"start_date": "2024-06-03",
"end_date": "2024-07-28",
"time_columns": [
"A",
"L",
"X",
"AG",
"AN"
"X"
]
}
],
"SAVE_ICS_PATH": "s24/core-courses",
"SAVE_JSON_PATH": "s24/core-courses.json"
"SAVE_ICS_PATH": "sum24/core-courses",
"SAVE_JSON_PATH": "sum24/core-courses.json"
}
22 changes: 9 additions & 13 deletions schedule/electives/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

from schedule.electives.config import electives_config as config
from schedule.electives.parser import ElectiveParser, convert_separation
from schedule.innohassle import Output, InNoHassleEventsClient, update_inh_event_groups
from schedule.models import PredefinedEventGroup, PredefinedTag
from schedule.innohassle import Output, InNoHassleEventsClient, update_inh_event_groups, CreateTag, CreateEventGroup
from schedule.processors.regex import sluggify
from schedule.utils import get_base_calendar

Expand Down Expand Up @@ -44,22 +43,20 @@
content = xlsx.read()
f.write(content)

semester_tag = PredefinedTag(
semester_tag = CreateTag(
alias=config.SEMESTER_TAG.alias,
type=config.SEMESTER_TAG.type,
name=config.SEMESTER_TAG.name,
)

elective_tag = PredefinedTag(
elective_tag = CreateTag(
alias="electives",
type="category",
name="Electives",
)
semester_tag_reference = semester_tag.reference
elective_tag_reference = elective_tag.reference
tags = [semester_tag, elective_tag]

predefined_event_groups: list[PredefinedEventGroup] = []
predefined_event_groups: list[CreateEventGroup] = []

mount_point = config.SAVE_ICS_PATH

Expand Down Expand Up @@ -87,15 +84,14 @@

elective_type_directory.mkdir(parents=True, exist_ok=True)

elective_type_tag = PredefinedTag(
elective_type_tag = CreateTag(
alias=sluggify(target.sheet_name),
type="electives",
name=target.sheet_name,
)

tags.append(elective_type_tag)

elective_type_tag_reference = elective_type_tag.reference

for calendar_name, events in converted.items():
calendar = get_base_calendar()
Expand Down Expand Up @@ -129,15 +125,15 @@
else:
description = f"Elective schedule for '{calendar_name}'"
predefined_event_groups.append(
PredefinedEventGroup(
CreateEventGroup(
alias=calendar_alias,
name=calendar_name,
description=description,
path=file_path.relative_to(config.MOUNT_POINT).as_posix(),
tags=[
elective_tag_reference,
elective_type_tag_reference,
semester_tag_reference,
elective_tag,
elective_type_tag,
semester_tag,
],
)
)
Expand Down
Loading

0 comments on commit 8ccce4e

Please sign in to comment.