Commit 4eaa2978 authored by Dominik Woiwode's avatar Dominik Woiwode
Browse files

Parse and implement folders

parent b4a922a7
......@@ -3,7 +3,7 @@ import hashlib
import os
from enum import Enum
from pathlib import Path
from typing import Optional
from typing import Optional, Dict, List
import requests
......@@ -74,7 +74,7 @@ class BasePad:
with open(path, "w", encoding="utf-8") as d:
d.write(content)
def compile(self, outFilePath, template: Template = None):
def compile(self, outFilePath, template: Template = None) -> int:
outPath = Path(outFilePath)
os.makedirs(outPath.parent, exist_ok=True)
metadataStr = " " + " ".join([f'-M {key}="{val}"' for key, val in self.metadata.items()])
......@@ -82,11 +82,12 @@ class BasePad:
if template is not None and template != Template.UNDEFINED:
templateStr = f' --template="{template.fullPath()}" '
cmd = f'pandoc "{self.rawPath}"{metadataStr}{templateStr}-o "{str(outPath.absolute())}"'
os.system(cmd)
return os.system(cmd)
class ProtocolPad(BasePad):
def __init__(self, source: SourceTypes, *_, date=None, isFachgruppenvollversammlung=False, isApproved=False):
def __init__(self, source: SourceTypes, *_, date: datetime.datetime = None,
isFachgruppenvollversammlung: bool = False, isApproved: bool = False):
super().__init__(source)
self.date = date
self.isApproved = isApproved
......@@ -95,39 +96,48 @@ class ProtocolPad(BasePad):
def __repr__(self):
return super(ProtocolPad, self).__repr__()[:-1] + f", {self.date})"
def sendMailAsApproved(self):
def sendMailAsApproved(self) -> bool:
pass
def sendMailAsUnapproved(self):
def sendMailAsUnapproved(self) -> bool:
pass
def uploadToCloud(self):
def uploadToCloud(self) -> bool:
pass
def uploadToGrav(self):
def uploadToGrav(self) -> bool:
pass
class AttachementPad(BasePad):
pass
def __init__(self, source: SourceTypes, name: str, date: datetime.datetime = None, version=0, isApproved=False):
super().__init__(source)
self.name = name
self.date = date
self.version = version
self.isApproved = isApproved
class PadCollection(BasePad):
def __init__(self, source: SourceTypes):
super().__init__(source)
def getPads(self):
def getPads(self) -> Dict[str, List[BasePad]]:
"""
Parsing the protocollink-Pad for urls.
"""
HTTPS = "https://"
pads = list()
pads = dict()
currentFolder = ""
for line in self.source.retrieveContent().split("\n"):
if line.startswith("# "):
currentFolder = line.split("#")[1].strip()
continue
pad = self.parsePad(line)
if pad is None:
continue
pads.append(pad)
if currentFolder not in pads:
pads[currentFolder] = list()
pads[currentFolder].append(pad)
return pads
......
......@@ -10,9 +10,8 @@ class ProtokollGUI(tk.Tk):
self.folders = dict()
self.folderIndex = 0
self.folders = {
"MainFolder": self.rootPad.getPads()
}
self.folders = self.rootPad.getPads()
self.currentPads = list()
self.topRow = tk.Frame(self)
self.topRow.pack(fill=tk.X, expand=True)
......@@ -33,14 +32,15 @@ class ProtokollGUI(tk.Tk):
def wrapper(*args,**kwargs):
self.folderIndex = (self.folderIndex + i) % len(self.folders)
self.updatePadFrame()
return wrapper
def updatePadFrame(self):
folderName = list(self.folders.keys())[self.folderIndex]
self.folderLabel.configure(text=folderName)
pads = self.folders[folderName]
for i, pad in enumerate(pads):
assert isinstance(pad, pter.ProtocolPad)
self.currentPads = self.folders[folderName]
for i, pad in enumerate(self.currentPads):
assert isinstance(pad, pter.ProtocolPad) or isinstance(pad, pter.AttachementPad)
tk.Label(self.padFrame, text=pad.source.url,anchor=tk.W, bg="red").grid(row=i,column=0, sticky=tk.W) # URL
tk.Label(self.padFrame, text=pad.date,anchor=tk.W, bg="blue").grid(row=i,column=1) # Date
# Button Download
......@@ -73,5 +73,6 @@ class ProtokollGUI(tk.Tk):
if __name__ == '__main__':
gui = ProtokollGUI(pter.LocalCache("data/rootPad.md"))
# gui = ProtokollGUI(pter.LocalCache("data/rootPad.md"))
gui = ProtokollGUI(pter.CodiMD("https://pad.finf.uni-hannover.de/protokolllinks_terces"))
gui.mainloop()
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