-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllp_obsidian.py
More file actions
97 lines (80 loc) · 2.91 KB
/
llp_obsidian.py
File metadata and controls
97 lines (80 loc) · 2.91 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
from ics import Calendar
import requests
import pandas as pd
import re
# Settings
## Studenplan URL CAVE: replace webcal with HTTP
cal_url = "http://lernziele.charite.de/zend/XXXXXX"
## Lernziel-Datei aus LLP
file_lernziele = "files/export.xlsx"
ignore_type = ["POL","MWS"]
only_future_events = True
ignore_holiday = True # Work-in-progress, no functionality as of now
## Obsidian settings
dailynote_format = "%Y-%m-%d"
dailynote_header = "# Uni"
target_path = "files/obsidian_export/"
write_mode = "w" # Use a(ppend) if files already exist
## Format String for LV-names
name_regex = "(.*! )?([äöüÄÖÜ\w]{1,5}.?):\s([\w\W]*)\s\(([\w\W]*),\s([\w\W]*)\)"
# Get Calendar items and convert to DataFrame
cal = Calendar(requests.get(cal_url).text)
e_names = []
e_begin = []
for e in cal.events:
e_names.append(e.name)
e_begin.append(e.begin)
events = pd.DataFrame({"name":e_names,"start":e_begin})
# Basic conversions and preparatory regex to the name column
events["date"] = pd.to_datetime(events.start, utc=True, format="%Y-%m-%dT%H:%M:%S+00:00")
events["name"] = events.name.str.replace("Vorlesung (Prolog|Epilog)","VL",regex=True)
events["name"] = events.name.str.replace("Prolog/ Epilog","P/E")
# Parse LV-name using regex
lv_isHoliday = [] #returns True if event is marked as on holiday (ENTFÄLLT - Feiertag)
lv_type = []
lv_name = []
lv_modul = []
lv_mw = [] #Modulwoche
for lv in events.name:
result = re.search(name_regex,lv)
if result.group(1): lv_isHoliday.append(True)
else: lv_isHoliday.append(False)
lv_type.append(result.group(2))
lv_name.append(result.group(3))
lv_modul.append(result.group(4))
lv_mw.append(result.group(5))
events["isHoliday"] = lv_isHoliday
events["lv_type"] = lv_type
events["lv_name"] = lv_name
events["lv_modul"] = lv_modul
events["lv_mw"] = lv_mw
# Delete ignored event types
events = events[~events.lv_type.isin(ignore_type)]
# Delete past events
if only_future_events:
events = events[events.date >= pd.Timestamp.now(tz="UTC")].reset_index()
# Import Lernziele
lz = pd.read_excel(file_lernziele)
events["Lernziele"] = ""
for i, e in events.iterrows():
list_lz = []
lz_select = lz.loc[lz["Veranstaltung: Titel"].str.contains(e.lv_name,regex=False)]
for lz_e in lz_select["Lernziel"]:
list_lz.append(lz_e)
events["Lernziele"].iloc[i] = list_lz
# Group for Obisdian into
# Dailynote
# ├── Veranstaltung
# ├── Lernziele
events.sort_values(by="date",inplace=True)
events_daily = events.groupby(events.date.dt.date)
for date, items in events_daily:
path = target_path + date.strftime(dailynote_format) + ".md"
print(f"creating {path}")
# Write dailynote files
with open(path, write_mode, encoding="utf-8") as f:
f.write(f"{dailynote_header}\n")
for i, e in items.iterrows():
f.write(f"## {e.lv_name} ({e.lv_type})\n")
for lz in e.Lernziele:
f.write(f"- {lz}\n")