9
9
import caldav as caldav
10
10
import cooltables
11
11
12
+
12
13
class LectioCalDavSynchronizer :
13
14
def __init__ (self , lec_inst_id , lec_username , lec_password , cal_url , cal_username , cal_password ) -> None :
14
15
"""Constructor for LectioCalDavSynchronizer
@@ -89,7 +90,13 @@ def _get_module_id(module: lectio.Module) -> str:
89
90
str: id from module url with lecmod prepended
90
91
"""
91
92
92
- return "lecmod" + re .search (r"absid=(.*?)&" , module .url )[1 ]
93
+ mod_id = ""
94
+ if module .url :
95
+ mod_id = re .search (r"absid=(.*?)&" , module .url )[1 ]
96
+ else :
97
+ mod_id = str (round (module .start_time .timestamp ()))
98
+
99
+ return "lecmod" + mod_id
93
100
94
101
def _get_module_title (self , module : lectio .Module ) -> str :
95
102
"""Get module title
@@ -101,15 +108,20 @@ def _get_module_title(self, module: lectio.Module) -> str:
101
108
str: module title
102
109
"""
103
110
104
- title = module .subject
105
- subject = module .subject .lower ()
111
+ title = ""
112
+ if module .subject :
113
+ title = module .subject
114
+ subject = module .subject .lower ()
115
+
116
+ for trans in self .team_translations .keys ():
117
+ if trans in subject :
118
+ title = self .team_translations .get (trans )
106
119
107
- for trans in set (self .team_translations .keys ()):
108
- if trans in subject :
109
- title = self .team_translations .get (trans )
120
+ if module .title :
121
+ title += ' - '
110
122
111
- if module .title is not None :
112
- title += f' - { module .title } '
123
+ if module .title :
124
+ title += module .title
113
125
if module .extra_info :
114
126
title += ' [+]'
115
127
@@ -130,9 +142,18 @@ def _get_module_desc(module: lectio.Module) -> str:
130
142
str: Module description, with url
131
143
"""
132
144
133
- desc = re .match (r"^(.*?)&" , module .url )[1 ]
145
+ desc = ""
146
+
147
+ # Add url at start if it exists
148
+ if module .url :
149
+ desc = re .match (r"^(.*?)&" , module .url )[1 ]
150
+
151
+ if module .extra_info :
152
+ desc += "\n \n " + module .extra_info
153
+
154
+ # Add extra info if it exists
134
155
if module .extra_info :
135
- desc += " \n \n " + module .extra_info
156
+ desc += module .extra_info
136
157
137
158
return desc .replace ("\r \n " , "\n " )
138
159
0 commit comments