Web M&M
https://mam.matfyz.cz
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.5 KiB
52 lines
1.5 KiB
#!/usr/bin/python
|
|
|
|
import psycopg2
|
|
import sys
|
|
import subprocess
|
|
import re
|
|
|
|
dbname="mam-prod"
|
|
user="mam"
|
|
|
|
conn = psycopg2.connect("dbname={0} user={1}".format(dbname,user))
|
|
cur = conn.cursor()
|
|
|
|
names = []
|
|
|
|
with open("obalky.sql") as qfile, open("obalky-template.tex") as texheader, open("obalky.tex","w") as texout :
|
|
texout.write(texheader.read())
|
|
cur.execute(qfile.read())
|
|
for row in cur.fetchall():
|
|
(muz,jmeno,prijmeni,skola,ulice,mesto,psc,stat)=row
|
|
if (stat=='CZ'):
|
|
stat = ""
|
|
elif (stat=='SK'):
|
|
stat = "Slovenská republika"
|
|
else:
|
|
print("Neznamy stat: {}\n".format(stat))
|
|
if (skola==None):
|
|
skola=""
|
|
psc = psc.replace(" ","")
|
|
psc = psc[0:3]+" "+psc[3:]
|
|
|
|
texout.write("\\obalka{{{0}}}{{{1}}}{{{2}}}{{{3}}}{{{4}}}{{{5}}}{{{6}}}\n".format(jmeno,prijmeni,skola,ulice,psc,mesto,stat))
|
|
names.append((jmeno,prijmeni))
|
|
texout.write("\\bye\n")
|
|
|
|
cur.close()
|
|
conn.close()
|
|
|
|
print("Spoustim csplain ...")
|
|
output = subprocess.check_output(["csplain","obalky.tex"],stderr=subprocess.STDOUT)
|
|
page = 0
|
|
for line in output.decode("utf-8").splitlines():
|
|
pmatch = re.search("\[([0-9]+)\]",line)
|
|
if pmatch:
|
|
page = int(pmatch.group(1))
|
|
errmatch = re.match("Overfull",line)
|
|
if errmatch:
|
|
print("Preteceni na strane",page,"u osoby",names[page][0],names[page][1])
|
|
|
|
print("Spoustim dvipdf ...")
|
|
subprocess.call(["dvipdf","obalky.dvi"])
|
|
print("Hotovo.")
|
|
|