-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
109 lines (97 loc) · 3.54 KB
/
Copy pathexample.py
File metadata and controls
109 lines (97 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import argparse
from datetime import datetime, timedelta, timezone
try:
from zoneinfo import ZoneInfo # type: ignore[attr-defined]
except ImportError: # pragma: no cover
ZoneInfo = None # type: ignore[assignment]
from modeus_client import ModeusClient
def main() -> None:
parser = argparse.ArgumentParser(description="Download Modeus schedule for the current user.")
parser.add_argument("--username", required=True, help="Login (e.g. stud0000xxxxxx@study.utmn.ru)")
parser.add_argument("--password", required=True, help="Account password")
parser.add_argument(
"--timezone",
default="UTC",
help="Timezone identifier used by the backend (defaults to UTC)",
)
parser.add_argument(
"--days",
type=int,
default=14,
help="Number of days forward to request (default: 14)",
)
parser.add_argument(
"--start",
type=str,
help="ISO8601 timestamp to start from (defaults to current moment, UTC)",
)
parser.add_argument(
"--page-size",
dest="page_size",
type=int,
default=200,
help="Maximum number of events per page (default: 200)",
)
parser.add_argument(
"--from-week-start",
action="store_true",
dest="from_week_start",
help="Start from the beginning of the current week (Monday 00:00 in the provided timezone).",
)
args = parser.parse_args()
start_value = args.start
if args.from_week_start:
tzinfo = timezone.utc
if ZoneInfo is not None:
try:
tzinfo = ZoneInfo(args.timezone)
except Exception:
tzinfo = timezone.utc
now = datetime.now(tzinfo)
week_start_local = now - timedelta(days=now.weekday())
week_start_local = week_start_local.replace(hour=0, minute=0, second=0, microsecond=0)
start_value = week_start_local.astimezone(timezone.utc).isoformat()
client = ModeusClient(args.username, args.password)
client.authenticate()
result = client.fetch_schedule(
timezone_name=args.timezone,
days=args.days,
start=start_value,
page_size=args.page_size,
)
events = result.get("events", [])
person_id = result.get("person_id") or "unknown"
print(f"Fetched {len(events)} events for person {person_id}.")
if not events:
return
for event in events:
title = event.get("title", "")
print(f"- {title}")
print(f" start: {event.get('start', '')}")
print(f" end: {event.get('end', '')}")
discipline = event.get("discipline")
if discipline:
print(f" discipline: {discipline}")
event_type = event.get("type")
if event_type:
print(f" type: {event_type}")
teachers = event.get("teachers") or []
if teachers:
print(f" teachers: {', '.join(teachers)}")
rooms = event.get("rooms") or []
if rooms:
locations = []
for room in rooms:
room_name = room.get("room") or ""
building_name = room.get("building") or ""
if room_name and building_name:
locations.append(f"{room_name} ({building_name})")
elif room_name:
locations.append(room_name)
elif building_name:
locations.append(building_name)
if locations:
print(f" locations: {', '.join(locations)}")
print()
if __name__ == "__main__":
main()