import jinja2
import os
import os.path
+import re
+import sys
conn = None
-env = jinja2.Environment(loader=jinja2.FileSystemLoader('templates'))
+env = jinja2.Environment(loader=jinja2.FileSystemLoader('templates', encoding='utf-8'))
+
+
+## jinja2 TeX espaping from http://flask.pocoo.org/snippets/55/
+LATEX_SUBS = [
+ (re.compile(r'\\'), r'\\textbackslash'),
+ (re.compile(r'([{}_#%&$])'), r'\\\1'),
+ (re.compile(r'~'), r'\~{}'),
+ (re.compile(r'\^'), r'\^{}'),
+ (re.compile(r'"'), r"''"),
+ (re.compile(r'\.\.\.+'), r'\\ldots'),
+]
+
+def escape_tex(value):
+ newval = value
+ for pattern, replacement in LATEX_SUBS:
+ newval = pattern.sub(replacement, newval)
+ return newval
+
+env.filters['escape_tex'] = escape_tex
+
def import_teilnehmer(input):
ids = set([ i[0] for i in conn.execute('SELECT id FROM teilnehmer').fetchall() ])
continue
if not int(row[0]) in ids:
print "Importing %s" % (row, )
- conn.execute("INSERT INTO teilnehmer VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
- row + [0, 0, 0])
+ conn.execute("INSERT INTO teilnehmer VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ row[:-2] + ['Kein T-Shirt', 'Kein Pulli'] + row[-2:] + [0, 0, 0, "", "false"])
conn.commit()
-
+
def mark_pay(outdir):
betrag = int(raw_input("Betrag: "))
if uid == "":
break
uid = int(uid)
+ vorname, nachname, email, bezahlt = \
+ conn.execute("SELECT vorname, nachname, email, bezahlt FROM teilnehmer WHERE id = ?", [uid]).fetchone()
+
+ if bezahlt == betrag:
+ continue
+
conn.execute("UPDATE teilnehmer SET bezahlt = ? WHERE id = ?", [betrag, uid])
- vorname, nachname, email = conn.execute("SELECT vorname, nachname, email FROM teilnehmer WHERE id = ?", [uid]).fetchone()
+
with open(os.path.join(outdir, email), 'w') as f:
f.write(template.render(vorname=vorname.decode('utf-8'),
preis, id])
conn.commit()
+def create_remind(outdir='output'):
+ def gen_rechnung(tshirt, zipper):
+ preis = 25
+ kosten = u""
+ kosten += u"%s | %s\n" % (u" Konferenzbeitrag".ljust(30), "25.00")
+ kosten += u"%s | %s\n" % ((u" T-Shirt (Größe %s)" % tshirt).ljust(30), " 0.00")
+ if zipper != 'Kein Pulli':
+ kosten += u"%s | %s\n" % ((u" Kapuzenzipper (Größe %s)" % zipper).ljust(30), "25.00")
+ preis += 25
+ kosten += ' '*2 + 29*'-' + '+' + 6*'-' + '\n'
+ kosten += u"%s | %s\n" % (u" Summe".ljust(30), "%2d.00" % preis)
+
+ return kosten, preis
+
+ def gen_token(id, vorname, nachname):
+ return u"%s-%s-%s" % (id, nachname.decode('utf-8').upper(), vorname.decode('utf-8').upper())
+
+ template = env.get_template('erinnerung.eml')
+
+ for id, vorname, nachname, email, tshirt, zipper in \
+ conn.execute("SELECT id, vorname, nachname, email, tshirt, zipper FROM teilnehmer " +
+ "WHERE bezahlt < 25 AND datetime(emailsent) < datetime(?)",
+ [(datetime.datetime.now() - datetime.timedelta(14)).isoformat()]):
+
+ rechnung, preis = gen_rechnung(tshirt, zipper)
+
+ with open(os.path.join(outdir, email), 'w') as f:
+ f.write(template.render(vorname=vorname.decode('utf-8'),
+ nachname=nachname.decode('utf-8'),
+ email=email.decode('utf-8'),
+ token=gen_token(id, vorname, nachname),
+ rechnung=rechnung).encode('utf-8'))
+
+ conn.execute("UPDATE teilnehmer set emailsent = ?, betrag = ? WHERE id = ?", [datetime.datetime.now().isoformat(),
+ preis, id])
+ conn.commit()
+
+
def create_nametag(outdir='output'):
template = env.get_template('nametag.svg')
-
- for vorname, nachname, namensschild, hochschule in \
- conn.execute("SELECT vorname, nachname, namensschild, hochschule FROM teilnehmer"):
- with open(os.path.join(outdir, "%s.svg" % namensschild), 'w') as f:
+ for teiln_id, vorname, nachname, namensschild, hochschule, dochned in \
+ conn.execute("SELECT id, vorname, nachname, namensschild, hochschule, dochned FROM teilnehmer"):
+
+ if dochned != "false":
+ print >> sys.stderr, "not generating %s %s (id %s), because abgemeldet" % (vorname, nachname, teiln_id)
+ continue
+
+ with open(os.path.join(outdir, "%s.svg" % teiln_id), 'w') as f:
f.write(template.render(name=u"%s %s" % (vorname.decode('utf-8'),
nachname.decode('utf-8')),
nick=namensschild.decode('utf-8'),
uni1=hochschule.decode('utf-8')).encode('utf-8'))
+
+def create_teilnehmer_list(outdir = 'output'):
+ template = env.get_template('teilnehmerliste.tex')
+
+ teilnehmer = []
+ for vor, nach, nick, hochschule, betrag, bezahlt, shirtsize, zippersize, dochned, comment in \
+ conn.execute("SELECT vorname, nachname, namensschild, hochschule, betrag, bezahlt, tshirt, zipper, dochned, orga_comment FROM teilnehmer ORDER BY UPPER(nachname) ASC"):
+
+ vor = vor.decode('utf8')
+ nach = nach.decode('utf8')
+ nick = nick.decode('utf8')
+ hochschule = hochschule.decode('utf8')
+ ## betrag ist schon int
+ ## bezahlt ist schon int
+ shirtsize = shirtsize.decode('utf8')
+ if re.match("kein", shirtsize, flags=re.IGNORECASE):
+ shirtsize = ""
+
+ zippersize = zippersize.decode('utf8')
+ if re.match("kein", zippersize, flags=re.IGNORECASE):
+ zippersize = ""
+
+ ## string to bool..
+ if dochned == "false":
+ will_attend = True
+ else:
+ will_attend = False
+ comment = comment.decode('utf8')
+
+ teilnehmer.append({'vorname': vor, 'nachname': nach,
+ 'hochschule': hochschule, 'nick': nick, 'betrag': betrag, 'bezahlt':
+ bezahlt, 'shirtsize': shirtsize, 'zippersize': zippersize,
+ 'will_attend': will_attend, 'comment': comment})
+
+
+ with open(os.path.join(outdir, "teilnehmerliste.tex"), 'w') as out:
+ out.write(template.render(teilnehmer=teilnehmer).encode('utf-8'))
+
+
+
+def create_bmbf_list(outdir = 'output'):
+ template = env.get_template('bmbf-unterschriftenliste.tex')
+
+
+ teilnehmer = []
+ i = 1
+ for vor, nach, hochschule in \
+ conn.execute("SELECT vorname, nachname, hochschule FROM teilnehmer ORDER BY UPPER(nachname) ASC"):
+
+ vor = vor.decode('utf8')
+ nach = nach.decode('utf8')
+ hochschule = hochschule.decode('utf8')
+
+ teilnehmer.append({'vorname': vor, 'nachname': nach, 'num': i, 'hochschule': hochschule})
+ i = i+1
+
+
+ with open(os.path.join(outdir, "bmbf-unterschriftenliste.tex"), 'w') as out:
+ out.write(template.render(teilnehmer=teilnehmer).encode('utf-8'))
+
+
def main():
parser = argparse.ArgumentParser(description="Ultimate Teilnehmertool")
help='Generiere E-Mails mit Überweisungsinformationen')
group.add_argument('--pay', action='store_true',
help='Speichere Zahlungseingang')
-
+ group.add_argument('--remind', action='store_true',
+ help='Generiere Zahlungsaufforderungserinnerung')
+ group.add_argument('--bmbf', action='store_true',
+ help='Generiere BMBF-Unterschriftenliste')
+ group.add_argument('--liste', action='store_true',
+ help='Generiere Teilnehmerübersichtsliste')
+
# Argumente
parser.add_argument('--db', default='teilnehmer.sqlite',
help='Teilnehmerdatenbank')
help='Eingabedatei')
parser.add_argument('-o', '--output', default='output',
help='Ausgabeverzeichnis')
-
+
args = parser.parse_args()
global conn
conn = sqlite3.connect(args.db)
conn.text_factory = str
+ conn.row_factory = sqlite3.Row
+ conn.execute('pragma encoding = "UTF-8";')
- if args.nametag or args.email or args.pay:
+ if args.nametag or args.email or args.pay or args.remind or args.bmbf or args.liste:
assert(args.output)
if not os.path.exists(args.output):
os.mkdir(args.output)
-
+
if args.nametag:
create_nametag(args.output)
elif args.email:
create_mail(args.output)
elif args.pay:
mark_pay(args.output)
+ elif args.remind:
+ create_remind(args.output)
+ elif args.bmbf:
+ create_bmbf_list(args.output)
+ elif args.liste:
+ create_teilnehmer_list(args.output)
elif args.importcsv:
assert(args.input)
if __name__ == '__main__':
main()
-
+
+# vim: set expandtab :