Commit d69be829 authored by Jakob Marten's avatar Jakob Marten
Browse files

Settings and semester added

parent ac4a89bf
......@@ -147,7 +147,48 @@ class GitHelper:
os.system(cmd)
class Semester:
def __init__(self, year: int, part: str, displayName: str = None):
self.year = year
self.part = part.upper()
self.displayName = displayName or self.DEFAULT_DISPLAY_NAME()
self.gravPath = self.DEFAULT_GRAV_PATH()
def DEFAULT_DISPLAY_NAME(self):
return "Wintersemester "+str(self.year)+"/"+str(self.year+1) if self.part == "WS" else "Sommersemester"+str(self.year)
def DEFAULT_GRAV_PATH(self):
return os.path.join(GIT_REPO_NAME, "pages", "fachrat", "02.protokolle", str(self.year)[2:] + self.part, "protocol_semester.de.md")
def tup(self):
return (self.year, self.part)
def uploadToGrav(self):
if os.path.exists(self.gravPath):
raise FileExistsError(f"{self.gravPath} already exists!")
os.makedirs(str(Path(self.gravPath).parent), exist_ok=True)
with open(self.gravPath, "w") as f:
f.write(f"---\ntitle: {self.displayName}\n---")
GIT_HELPER.add("pages/")
GIT_HELPER.commit(f"Added semester {self.part} {self.year}")
GIT_HELPER.push()
@staticmethod
def getSemesterTuple(date: datetime.datetime):
if date.month > 3 and date.month < 10:
# summer
return (str(date.year)[2:], "SS")
elif date.month >= 10:
# winter
return (str(date.year)[2:], "WS")
else:
# winter
return (str(date.year-1)[2:], "WS")
# === Source Types ===
class SourceTypes:
def __init__(self, url: str):
self.url: str = url
......@@ -239,6 +280,7 @@ class ProtocolPad(BasePad):
self.date = date
self.isApproved = isApproved
self.isFachgruppenvollversammlung = isFachgruppenvollversammlung
self.semester = None
super().__init__(source)
def __repr__(self):
......@@ -248,7 +290,7 @@ class ProtocolPad(BasePad):
return f"Protokoll {self.gremium.name} {self.date.strftime('%Y-%m-%d')}" + " - Fachgruppenvollversammlung"*self.isFachgruppenvollversammlung
def DEFAULT_GRAV_PATH(self):
return os.path.join(GIT_REPO_NAME, "pages", "fachrat", "02.protokolle", self.folder, self.date.strftime("%Y-%m-%d")+"-fgvv"*self.isFachgruppenvollversammlung, "default.de.md")
return os.path.join(GIT_REPO_NAME, "pages", "fachrat", "02.protokolle", str(self.year)[2:] + self.part, self.date.strftime("%Y-%m-%d")+"-fgvv"*self.isFachgruppenvollversammlung, "default.de.md")
def sendMailAsUnapproved(self) -> bool:
sender = MailParticipant(LDAP_MAIL, LDAP_NAME)
......@@ -293,6 +335,7 @@ class ProtocolPad(BasePad):
def uploadToGrav(self):
# TODO: better file management
self.semester.uploadToGrav()
if not os.path.exists(self.DEFAULT_RAW_PATH()):
raise FileNotFoundError(f"{self.DEFAULT_RAW_PATH()} doesn't exist")
self.rawPath = self.DEFAULT_RAW_PATH()
......@@ -370,6 +413,7 @@ class PadCollection(BasePad):
Parsing the protocollink-Pad for urls.
"""
pads = dict()
semesters = dict()
currentFolder = ""
for line in self.source.retrieveContent().split("\n"):
if line.startswith("# "):
......@@ -380,6 +424,11 @@ class PadCollection(BasePad):
continue
if currentFolder not in pads:
pads[currentFolder] = list()
if pad.date != None:
semTuple = Semester.getSemesterTuple(pad.date)
if semTuple not in semesters:
semesters[semTuple] = Semester(semTuple[0], semTuple[1])
pad.semester = semesters[semTuple]
pad.folder = currentFolder
pads[currentFolder].append(pad)
......
import linkToPDF2 as pter
pter.DEFAULT_GREMIUM = None
pter.LDAP_USER = None
pter.LDAP_PASSWORD = None
pter.LDAP_MAIL = None
pter.LDAP_NAME = None
pter.GIT_REPO = None
pter.GIT_REPO_NAME = None
pter.GIT_NAME = None
pter.GIT_EMAIL = None
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment