2019-05-01 10:48:57 +02:00
|
|
|
#!/usr/bin/env python3
|
2019-02-23 16:29:40 +01:00
|
|
|
from fdfgen import forge_fdf
|
|
|
|
import sh
|
|
|
|
from math import ceil
|
|
|
|
import csv
|
|
|
|
from operator import itemgetter
|
2019-05-01 10:48:57 +02:00
|
|
|
from pathlib import Path
|
2019-02-23 16:29:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
######## Bitte hier Anpassen ##########################################
|
|
|
|
maßnahmenzeitraum = "09. - 13.05.18"
|
|
|
|
datum="09.05.18"
|
|
|
|
kif_ev= "Verein zur Förderung d. Konferenz d. deutschspr. Informatikfachschaften e.V."
|
|
|
|
maßname="46.0 Konferenz der deutschsprachtigen Informatikfachschaften"
|
2019-05-01 10:48:57 +02:00
|
|
|
csv_file_name="teilnehmer_innen.csv"
|
2019-02-23 16:29:40 +01:00
|
|
|
leer_blaetter=2
|
2019-05-01 10:48:57 +02:00
|
|
|
vorlage = "Vorlage_BMBF_Listen_2019.pdf"
|
2019-02-23 16:29:40 +01:00
|
|
|
datum_list = ["09.05.18","10.05.18","11.05.18","12.05.18","13.05.18",]
|
|
|
|
|
|
|
|
|
|
|
|
######## Nothing to change below here ##########################################
|
|
|
|
|
|
|
|
form_mapping = [("6","20","21"),("19","40","41"),("18","39","22"),
|
|
|
|
("17","42","23"),("16","43","24"),("15","44","25"),("14","45","26"),
|
|
|
|
("13","46","27"),("12","Text7","28"),("11","29","34"),("10","30","35"),
|
|
|
|
("9","31","36"),("8","32","37"),("7","33","38")]
|
|
|
|
|
|
|
|
|
|
|
|
def readcsv(csv_file_name):
|
|
|
|
persons = []
|
2019-05-01 10:48:57 +02:00
|
|
|
try:
|
|
|
|
csvfile = open(csv_file_name,newline='')
|
|
|
|
except FileNotFoundError:
|
|
|
|
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"))
|
2019-02-23 16:29:40 +01:00
|
|
|
|
|
|
|
return persons
|
|
|
|
|
|
|
|
|
|
|
|
def generate_pdfs(persons, maßnahmenzeitraum, datum, kif_ev, maßname, leer_blaetter):
|
|
|
|
seite = 1
|
|
|
|
data_file="data_fdf.bin"
|
|
|
|
output_file_name="output"
|
|
|
|
personen_pro_seite = 14
|
|
|
|
|
2019-05-01 10:48:57 +02:00
|
|
|
#check if vorlage exits
|
|
|
|
test_file = Path(vorlage)
|
|
|
|
if not test_file.is_file():
|
|
|
|
print("[X] File {} not found!".format(vorlage))
|
|
|
|
exit(-1)
|
|
|
|
|
2019-02-23 16:29:40 +01:00
|
|
|
anzahl_seiten = ceil(len(persons)/personen_pro_seite)
|
|
|
|
pdfs = []
|
|
|
|
|
|
|
|
for j in range(anzahl_seiten+leer_blaetter):
|
|
|
|
felder = []
|
|
|
|
i=0
|
|
|
|
for item in form_mapping:
|
|
|
|
if personen_pro_seite*j+i < len(persons):
|
|
|
|
felder.append((item[0],str(j*personen_pro_seite+i+1)))
|
|
|
|
felder.append((item[1], persons[j*personen_pro_seite+i]["Name"]))
|
2019-05-01 10:48:57 +02:00
|
|
|
felder.append((item[2], persons[j*personen_pro_seite+i]["Hochschule"]))
|
2019-02-23 16:29:40 +01:00
|
|
|
i+=1
|
|
|
|
|
|
|
|
if i == personen_pro_seite:
|
|
|
|
output_file = output_file_name + str(seite) +".pdf"
|
|
|
|
|
|
|
|
headers = [("1", seite), ("2", maßnahmenzeitraum), ("3", datum), ("4", kif_ev), ("5", maßname)]
|
|
|
|
|
|
|
|
fields = felder + headers
|
|
|
|
|
|
|
|
|
|
|
|
fdf = forge_fdf("",fields,[],[],[])
|
|
|
|
fdf_file = open(data_file,"wb")
|
|
|
|
fdf_file.write(fdf)
|
|
|
|
fdf_file.close()
|
|
|
|
|
2019-05-01 10:48:57 +02:00
|
|
|
sh.pdftk(vorlage,"fill_form", data_file,"output",output_file,"flatten")
|
2019-02-23 16:29:40 +01:00
|
|
|
|
|
|
|
pdfs.append(output_file)
|
|
|
|
|
|
|
|
seite+=1
|
|
|
|
|
|
|
|
|
|
|
|
return pdfs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
person_list = readcsv(csv_file_name)
|
|
|
|
for datum in datum_list:
|
2019-05-01 10:48:57 +02:00
|
|
|
final_pdf_name = "teilnehmendenliste_{}.pdf".format(datum.replace(". ", "_"))
|
2019-02-23 16:29:40 +01:00
|
|
|
output_files = generate_pdfs(person_list, maßnahmenzeitraum, datum, kif_ev, maßname, leer_blaetter)
|
|
|
|
sh.pdftk(output_files, "cat","output",final_pdf_name )
|
|
|
|
|
|
|
|
|
|
|
|
|