Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify slides #42

Merged
merged 2 commits into from
Apr 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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