Adjust to 2019 template, add error handling, fix some naming
This commit is contained in:
parent
497d25ea57
commit
e1a8002f27
3 changed files with 27 additions and 12 deletions
|
@ -1,11 +1,10 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
from fdfgen import forge_fdf
|
from fdfgen import forge_fdf
|
||||||
import sh
|
import sh
|
||||||
from math import ceil
|
from math import ceil
|
||||||
import csv
|
import csv
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
import click
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,9 +13,9 @@ maßnahmenzeitraum = "09. - 13.05.18"
|
||||||
datum="09.05.18"
|
datum="09.05.18"
|
||||||
kif_ev= "Verein zur Förderung d. Konferenz d. deutschspr. Informatikfachschaften e.V."
|
kif_ev= "Verein zur Förderung d. Konferenz d. deutschspr. Informatikfachschaften e.V."
|
||||||
maßname="46.0 Konferenz der deutschsprachtigen Informatikfachschaften"
|
maßname="46.0 Konferenz der deutschsprachtigen Informatikfachschaften"
|
||||||
csv_file_name="kif_460.csv"
|
csv_file_name="teilnehmer_innen.csv"
|
||||||
leer_blaetter=2
|
leer_blaetter=2
|
||||||
|
vorlage = "Vorlage_BMBF_Listen_2019.pdf"
|
||||||
datum_list = ["09.05.18","10.05.18","11.05.18","12.05.18","13.05.18",]
|
datum_list = ["09.05.18","10.05.18","11.05.18","12.05.18","13.05.18",]
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,10 +29,16 @@ form_mapping = [("6","20","21"),("19","40","41"),("18","39","22"),
|
||||||
|
|
||||||
def readcsv(csv_file_name):
|
def readcsv(csv_file_name):
|
||||||
persons = []
|
persons = []
|
||||||
with open(csv_file_name, newline='') as csvfile:
|
try:
|
||||||
reader = csv.reader(csvfile, delimiter=",")
|
csvfile = open(csv_file_name,newline='')
|
||||||
persons = [{"Name":t[0],"Uni":t[1]} for t in reader if t[0] != "Name"]
|
except FileNotFoundError:
|
||||||
persons.sort(key=itemgetter("Uni","Name"))
|
print("[X] File {} not found!".format(csv_file_name))
|
||||||
|
exit(-1)
|
||||||
|
else:
|
||||||
|
with csvfile:
|
||||||
|
reader = csv.reader(csvfile, delimiter=",")
|
||||||
|
persons = [{"Name":t[0],"Hochschule":t[1]} for t in reader if t[0] != "Name"]
|
||||||
|
persons.sort(key=itemgetter("Hochschule","Name"))
|
||||||
|
|
||||||
return persons
|
return persons
|
||||||
|
|
||||||
|
@ -44,6 +49,12 @@ def generate_pdfs(persons, maßnahmenzeitraum, datum, kif_ev, maßname, leer_bla
|
||||||
output_file_name="output"
|
output_file_name="output"
|
||||||
personen_pro_seite = 14
|
personen_pro_seite = 14
|
||||||
|
|
||||||
|
#check if vorlage exits
|
||||||
|
test_file = Path(vorlage)
|
||||||
|
if not test_file.is_file():
|
||||||
|
print("[X] File {} not found!".format(vorlage))
|
||||||
|
exit(-1)
|
||||||
|
|
||||||
anzahl_seiten = ceil(len(persons)/personen_pro_seite)
|
anzahl_seiten = ceil(len(persons)/personen_pro_seite)
|
||||||
pdfs = []
|
pdfs = []
|
||||||
|
|
||||||
|
@ -54,7 +65,7 @@ def generate_pdfs(persons, maßnahmenzeitraum, datum, kif_ev, maßname, leer_bla
|
||||||
if personen_pro_seite*j+i < len(persons):
|
if personen_pro_seite*j+i < len(persons):
|
||||||
felder.append((item[0],str(j*personen_pro_seite+i+1)))
|
felder.append((item[0],str(j*personen_pro_seite+i+1)))
|
||||||
felder.append((item[1], persons[j*personen_pro_seite+i]["Name"]))
|
felder.append((item[1], persons[j*personen_pro_seite+i]["Name"]))
|
||||||
felder.append((item[2], persons[j*personen_pro_seite+i]["Uni"]))
|
felder.append((item[2], persons[j*personen_pro_seite+i]["Hochschule"]))
|
||||||
i+=1
|
i+=1
|
||||||
|
|
||||||
if i == personen_pro_seite:
|
if i == personen_pro_seite:
|
||||||
|
@ -70,7 +81,7 @@ def generate_pdfs(persons, maßnahmenzeitraum, datum, kif_ev, maßname, leer_bla
|
||||||
fdf_file.write(fdf)
|
fdf_file.write(fdf)
|
||||||
fdf_file.close()
|
fdf_file.close()
|
||||||
|
|
||||||
sh.pdftk("Vorlage_BMBF_Listen.pdf","fill_form", data_file,"output",output_file,"flatten")
|
sh.pdftk(vorlage,"fill_form", data_file,"output",output_file,"flatten")
|
||||||
|
|
||||||
pdfs.append(output_file)
|
pdfs.append(output_file)
|
||||||
|
|
||||||
|
@ -84,7 +95,7 @@ def generate_pdfs(persons, maßnahmenzeitraum, datum, kif_ev, maßname, leer_bla
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
person_list = readcsv(csv_file_name)
|
person_list = readcsv(csv_file_name)
|
||||||
for datum in datum_list:
|
for datum in datum_list:
|
||||||
final_pdf_name = "teilnehmerliste_{}.pdf".format(datum.replace(". ", "_"))
|
final_pdf_name = "teilnehmendenliste_{}.pdf".format(datum.replace(". ", "_"))
|
||||||
output_files = generate_pdfs(person_list, maßnahmenzeitraum, datum, kif_ev, maßname, leer_blaetter)
|
output_files = generate_pdfs(person_list, maßnahmenzeitraum, datum, kif_ev, maßname, leer_blaetter)
|
||||||
sh.pdftk(output_files, "cat","output",final_pdf_name )
|
sh.pdftk(output_files, "cat","output",final_pdf_name )
|
||||||
|
|
||||||
|
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
fdfgen
|
||||||
|
sh
|
2
teilnehmer_innen.csv
Normal file
2
teilnehmer_innen.csv
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Kia Killing, Frei Universität Mordor
|
||||||
|
Lio Lampe, Sonnige Hochschule des Auenlandes
|
|
Loading…
Reference in a new issue