Created
June 12, 2017 14:02
-
-
Save lindemann09/0f6b61d1aff92b354906717c2865439b to your computer and use it in GitHub Desktop.
Generate subject hour vouchers via with Python and PDFlatex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: iso-8859-1 -*- | |
""" | |
Generate tex files with subject hour vouchers and a code list | |
and run pdflatex. | |
Version 0.5 | |
(c) 2012-2015, Oliver Lindemann | |
""" | |
import os | |
import time | |
import uuid | |
from datetime import date | |
from sets import Set | |
from random import randint | |
def today(): | |
rtn = time.asctime()[8:10].replace(' ', '0') | |
rtn += time.asctime()[3:8] | |
rtn += time.asctime()[-4:] | |
return rtn | |
def generate_code_list(number_of_codes, start_letter): | |
""" returns a list of unique participantion codes | |
Keyword arguments: | |
number_of_codes -- integer | |
""" | |
lst = Set() | |
cnt = randint(10,99)*100 | |
while len(lst) < number_of_codes: | |
u = uuid.uuid4() | |
cnt += 1 | |
lst.add( "{2}-{0}-{1}".format(cnt, u.hex[0:4], start_letter) ) | |
rtn = [] | |
rtn.extend(lst) | |
rtn.sort() | |
return rtn | |
print "* Credit Point Vouchers *" | |
name = raw_input("Investigator name: ") | |
n = int(raw_input("Number of vouchers: ")) | |
points = raw_input("Credit points per voucher: ") | |
flname = "{0}_{1}_{2}x{3}h".format(name, str(date.today()), n, points) | |
voucher_fl = flname + ".voucher.tex" | |
codelist_fl = flname + ".codelist.tex" | |
fl1 = open(voucher_fl , 'w+') | |
fl2 = open(codelist_fl, 'w+') | |
txt = """ | |
\\documentclass[a4paper,german]{article} | |
\\usepackage[T1]{fontenc} | |
\\usepackage[utf8]{inputenc} | |
\\begin{document} | |
\\noindent | |
""" | |
fl1.write(txt) | |
fl2.write(txt) | |
fl2.write("\\section*{VP-Stundenkodes, " +\ | |
"{0} ({1})".format(name, today()) +\ | |
"""} | |
\large\\bf | |
""") | |
if float(points)>1: | |
vp_stunde_txt = "{0} Versuchspersonenstunden".format(points) | |
else: | |
vp_stunde_txt = "{0} Versuchspersonenstunde".format(points) | |
for cnt,code in enumerate(generate_code_list(n,name[0:2].upper())): | |
fl1.write(""" | |
\\begin{minipage}{\\textwidth} | |
\\subsection*{Teilnahmebescheinigung, """+ vp_stunde_txt + """} | |
Sie erhalten \\textit{""" + vp_stunde_txt + """} gegen Unterschrift im | |
Sekretariat der Abteilung Kognitionswissenschaften (Frau Köhler, Campus Golm, | |
Haus 14, Raum 6.06 und 4.05). Versuchspersonenstunden sind nicht übertragbar. | |
\\vspace{5em}\\noindent | |
""") | |
fl1.write("(Name der/des Proband/in)\\hfill (Unterschrift Versuchsleiter/in)") | |
fl1.write ("\n\\newline\\hbox{}\\hfill{}\\textbf{") | |
fl1.write("{0}".format(code)) | |
fl1.write("}") | |
fl1.write("\\end{minipage}\\vspace{3em}") | |
fl2.write("\\makebox[15em][l]{") | |
fl2.write("{0}".format(code)) | |
fl2.write("}") | |
if cnt %2 == 1: | |
fl2.write("\\newline \n") | |
if cnt %10 == 9: | |
fl2.write("\\vspace{1em}\n") | |
fl1.write("\\end{document}") | |
fl2.write("\\end{document}") | |
fl1.close() | |
fl2.close() | |
# Run pdflatex | |
os.system("pdflatex " + voucher_fl) | |
os.system("pdflatex " + codelist_fl) | |
os.system("rm *.aux *.log *.tex") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment