implement things
This commit is contained in:
parent
4c17b5137f
commit
4b5308e936
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,5 @@
|
|||||||
# Calendar files
|
# Calendar files
|
||||||
calendar.ics
|
cal.ics
|
||||||
# Config file
|
# Config file
|
||||||
config.yml
|
config.yml
|
||||||
|
|
||||||
|
@ -4,94 +4,95 @@
|
|||||||
|
|
||||||
# List of subjects
|
# List of subjects
|
||||||
subjects:
|
subjects:
|
||||||
- name: Gym
|
gym:
|
||||||
id: gym
|
name: Gym
|
||||||
|
|
||||||
- name: Maths
|
mat:
|
||||||
id: mat
|
name: Maths
|
||||||
|
|
||||||
- name: French
|
fr:
|
||||||
id: fr
|
name: French
|
||||||
|
|
||||||
- name: Chemistry
|
chem:
|
||||||
id: chem
|
name: Chemistry
|
||||||
|
|
||||||
- name: Physics
|
phys:
|
||||||
id: phys
|
name: Physics
|
||||||
|
|
||||||
- name: Contemporary world
|
world:
|
||||||
id: world
|
name: Contemporary world
|
||||||
|
|
||||||
- name: Info
|
info:
|
||||||
id: info
|
name: Info
|
||||||
|
|
||||||
- name: Drama
|
dram:
|
||||||
id: dram
|
name: drama
|
||||||
|
|
||||||
- name: ECR
|
ecr:
|
||||||
id: ecr
|
name: ECR
|
||||||
|
|
||||||
- name: English
|
en:
|
||||||
id: en
|
name: English
|
||||||
|
|
||||||
- name: Music
|
mus:
|
||||||
id: mus
|
name: Music
|
||||||
|
|
||||||
# the cycle is postponed on these days
|
# the cycle is postponed on these days
|
||||||
|
# make sure to format dates exactly like this (otherwise it won't be parsed as a date!)
|
||||||
vacation_days:
|
vacation_days:
|
||||||
- single: 2023-9-4
|
- single: 2023-09-04
|
||||||
|
|
||||||
- single: 2023-10-9
|
- single: 2023-10-09
|
||||||
|
|
||||||
- start: 2023-10-30
|
- start: 2023-10-30
|
||||||
end: 2023-11-3
|
end: 2023-11-03
|
||||||
|
|
||||||
- single: 2023-11-17
|
- single: 2023-11-17
|
||||||
|
|
||||||
- single: 2023-11-24
|
- single: 2023-11-24
|
||||||
|
|
||||||
- start: 2023-12-25
|
- start: 2023-12-25
|
||||||
end: 2024-1-8
|
end: 2024-01-08
|
||||||
|
|
||||||
- start: 2024-1-29
|
- start: 2024-01-29
|
||||||
end: 2024-2-5
|
end: 2024-02-05
|
||||||
|
|
||||||
- start: 2024-3-1
|
- start: 2024-03-01
|
||||||
end: 2024-3-10
|
end: 2024-03-10
|
||||||
|
|
||||||
- start: 2024-3-29
|
- start: 2024-03-29
|
||||||
end: 2024-4-5
|
end: 2024-04-05
|
||||||
|
|
||||||
- single: 2024-4-19
|
- single: 2024-04-19
|
||||||
|
|
||||||
- start: 2024-5-17
|
- start: 2024-05-17
|
||||||
end: 2024-5-20
|
end: 2024-05-21
|
||||||
|
|
||||||
start_date: 2023-8-24
|
start_date: 2023-08-25
|
||||||
end_date: 2024-6-20
|
end_date: 2024-06-06
|
||||||
|
|
||||||
schedule_slots:
|
schedule_slots:
|
||||||
- start: 8:45
|
- start: '08:45'
|
||||||
end: 9:30
|
end: '09:30'
|
||||||
- start: 9:30
|
- start: '09:30'
|
||||||
end: 10:15
|
end: '10:15'
|
||||||
|
|
||||||
- start: 10:30
|
- start: '10:30'
|
||||||
end: 11:15
|
end: '11:15'
|
||||||
- start: 11:15
|
- start: '11:15'
|
||||||
end: 12:00
|
end: '12:00'
|
||||||
|
|
||||||
- start: 13:00
|
- start: '13:00'
|
||||||
end: 13:45
|
end: '13:45'
|
||||||
- start: 13:45
|
- start: '13:45'
|
||||||
end: 14:30
|
end: '14:30'
|
||||||
|
|
||||||
- start: 14:45
|
- start: '14:45'
|
||||||
end: 15:45
|
end: '15:45'
|
||||||
|
|
||||||
# short classes are 1 timeslot, otherwise 2
|
# short classes are 1 timeslot, otherwise 2
|
||||||
schedule:
|
schedule:
|
||||||
- day: 1
|
1:
|
||||||
classes:
|
classes:
|
||||||
- id: fr
|
- id: fr
|
||||||
loc: 360
|
loc: 360
|
||||||
@ -105,7 +106,7 @@ schedule:
|
|||||||
short: true
|
short: true
|
||||||
- id: chem
|
- id: chem
|
||||||
loc: 364
|
loc: 364
|
||||||
- day: 2
|
2:
|
||||||
classes:
|
classes:
|
||||||
- id: en
|
- id: en
|
||||||
loc: 368
|
loc: 368
|
||||||
@ -115,7 +116,7 @@ schedule:
|
|||||||
loc: 362
|
loc: 362
|
||||||
- id: info
|
- id: info
|
||||||
loc: Info room
|
loc: Info room
|
||||||
- day: 3
|
3:
|
||||||
classes:
|
classes:
|
||||||
- id: gym
|
- id: gym
|
||||||
loc: Gym 4
|
loc: Gym 4
|
||||||
@ -125,7 +126,7 @@ schedule:
|
|||||||
loc: Drama room
|
loc: Drama room
|
||||||
- id: mat
|
- id: mat
|
||||||
loc: 362
|
loc: 362
|
||||||
- day: 4
|
4:
|
||||||
classes:
|
classes:
|
||||||
- id: mat
|
- id: mat
|
||||||
loc: 362
|
loc: 362
|
||||||
@ -135,7 +136,7 @@ schedule:
|
|||||||
loc: 368
|
loc: 368
|
||||||
- id: chem
|
- id: chem
|
||||||
loc: 364
|
loc: 364
|
||||||
- day: 5
|
5:
|
||||||
classes:
|
classes:
|
||||||
- id: fr
|
- id: fr
|
||||||
loc: 360
|
loc: 360
|
||||||
@ -145,7 +146,7 @@ schedule:
|
|||||||
loc: 362
|
loc: 362
|
||||||
- id: fr
|
- id: fr
|
||||||
loc: 360
|
loc: 360
|
||||||
- day: 6
|
6:
|
||||||
classes:
|
classes:
|
||||||
- id: phys
|
- id: phys
|
||||||
loc: 364
|
loc: 364
|
||||||
|
80
main.py
Normal file
80
main.py
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
from ics import Calendar, Event
|
||||||
|
import arrow
|
||||||
|
import datetime
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
with open("config.yml") as f:
|
||||||
|
conf = yaml.safe_load(f.read())
|
||||||
|
|
||||||
|
subjects = conf["subjects"]
|
||||||
|
vacation_days = conf["vacation_days"]
|
||||||
|
start_date = conf["start_date"]
|
||||||
|
end_date = conf["end_date"]
|
||||||
|
schedule_slots = conf["schedule_slots"]
|
||||||
|
schedule = conf["schedule"]
|
||||||
|
|
||||||
|
step = datetime.timedelta(days = 1)
|
||||||
|
# cycle-day (e.g. 1-6)
|
||||||
|
day = 1
|
||||||
|
|
||||||
|
cal = Calendar()
|
||||||
|
|
||||||
|
current_date = start_date
|
||||||
|
|
||||||
|
while current_date <= end_date:
|
||||||
|
have_school = True
|
||||||
|
# Vacations
|
||||||
|
for vacation in vacation_days:
|
||||||
|
if(not vacation.get("single")):
|
||||||
|
if current_date >= vacation["start"] and current_date <= vacation["end"]:
|
||||||
|
have_school = False
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
if current_date == vacation["single"]:
|
||||||
|
have_school = False
|
||||||
|
break
|
||||||
|
# Weekends
|
||||||
|
if current_date.weekday() == 5 or current_date.weekday() == 6:
|
||||||
|
have_school = False
|
||||||
|
|
||||||
|
if not have_school:
|
||||||
|
current_date += step
|
||||||
|
continue
|
||||||
|
|
||||||
|
day_classes = schedule[day]["classes"]
|
||||||
|
|
||||||
|
slot_idx = 0
|
||||||
|
for subject_idx, sched_subject in enumerate(day_classes):
|
||||||
|
subject_id = sched_subject["id"]
|
||||||
|
subject_loc = sched_subject["loc"]
|
||||||
|
is_short = sched_subject.get("short", False)
|
||||||
|
|
||||||
|
subject = subjects[subject_id]
|
||||||
|
|
||||||
|
start_time = schedule_slots[slot_idx]["start"]
|
||||||
|
end_time = schedule_slots[slot_idx]["end"]
|
||||||
|
|
||||||
|
slot_idx += 1
|
||||||
|
if slot_idx >= len(schedule_slots):
|
||||||
|
slot_idx = len(schedule_slots) - 1
|
||||||
|
|
||||||
|
if not is_short:
|
||||||
|
end_time = schedule_slots[slot_idx]["end"]
|
||||||
|
slot_idx += 1
|
||||||
|
|
||||||
|
ev = Event()
|
||||||
|
ev.begin = arrow.get(f"{current_date} {start_time}", tzinfo="local")
|
||||||
|
ev.end = arrow.get(f"{current_date} {end_time}", tzinfo="local")
|
||||||
|
ev.location = str(subject_loc)
|
||||||
|
ev.description = f"Day {day}, {subject_loc}"
|
||||||
|
ev.name = subjects[subject_id]["name"]
|
||||||
|
cal.events.add(ev)
|
||||||
|
|
||||||
|
day += 1
|
||||||
|
if day > len(schedule):
|
||||||
|
day = 1
|
||||||
|
|
||||||
|
current_date += step
|
||||||
|
|
||||||
|
with open("cal.ics", "w") as f:
|
||||||
|
f.writelines(cal.serialize_iter())
|
@ -2,5 +2,6 @@ arrow==1.2.3
|
|||||||
attrs==23.1.0
|
attrs==23.1.0
|
||||||
ics==0.7.2
|
ics==0.7.2
|
||||||
python-dateutil==2.8.2
|
python-dateutil==2.8.2
|
||||||
|
PyYAML==6.0.1
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
TatSu==5.8.3
|
TatSu==5.8.3
|
||||||
|
Loading…
Reference in New Issue
Block a user