Skip to content

Commit

Permalink
Merge pull request #42 from automl-edu/unify_slides
Browse files Browse the repository at this point in the history
Unify slides
  • Loading branch information
mlindauer authored Apr 29, 2021
2 parents 675075a + 095835d commit 2cb3fb0
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions slides.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import subprocess
import multiprocessing


try:
subprocess.run("pdftk", capture_output=True)
PDFTK_INSTALLED = True
Expand Down Expand Up @@ -34,6 +35,30 @@ def copy():
with copy_destination.open("wb") as d:
d.write(content)

#sorts the values(paths) of the dict created in weekly and full slides
def sort_paths(plist):
for i in range(1, len(plist)):
j = i-1
nxt_element = plist[i]
#get the slide numbers
number1 = int(''.join(filter(str.isdigit, nxt_element.name)))
number2 = int(''.join(filter(str.isdigit, plist[j].name)))

if number1 >= 10:
number1 /= 10

if number2 >= 10:
number2 /= 10

while number2 > number1 and j >= 0:
plist[j+1] = plist[j]
j = j - 1
number2 = int(''.join(filter(str.isdigit, plist[j].name)))

if number2 >= 10:
number2 /= 10
plist[j+1] = nxt_element


def weekly_slides():
assert_pdftk()
Expand All @@ -44,7 +69,9 @@ def weekly_slides():
if week_number not in sources:
sources[week_number] = (file.parent.name, [])
sources[week_number][1].append(file)

for key in sources:
sort_paths(sources[key][1])

for week_name, sources in sources.values():
pdftk(sources, DST_FOLDER / f"{week_name}.pdf", Author=PDF_AUTHOR, Title=week_name.replace("_", " - ").title())

Expand All @@ -53,10 +80,22 @@ def full_slides():
assert_pdftk()
DST_FOLDER.mkdir(parents=True, exist_ok=True)

sources = []
sources = {}
for file, week_number, slide_number in iter_all():
sources.append(file)
pdftk(sources, DST_FOLDER / f"{FULL_PDF_NAME}.pdf", Author=PDF_AUTHOR, Title=FULL_PDF_NAME)
if week_number not in sources:
sources[week_number]= (file.parent.name, [])
sources[week_number][1].append(file)
for key in sources:
sort_paths(sources[key][1])


key_list= list(sources)
key_list.sort()
sources_list= list()
for i in key_list:
sources_list.extend(sources[i][1])

pdftk(sources_list, DST_FOLDER / f"{FULL_PDF_NAME}.pdf", Author=PDF_AUTHOR, Title=FULL_PDF_NAME)


def compile_all():
Expand Down

0 comments on commit 2cb3fb0

Please sign in to comment.