Skip to content

Instantly share code, notes, and snippets.

@ninux
Created February 3, 2013 03:07
Show Gist options
  • Save ninux/4700391 to your computer and use it in GitHub Desktop.
Save ninux/4700391 to your computer and use it in GitHub Desktop.
seribrief python, sqlite und latex
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3 as lite
import sys
import os
con = lite.connect('datenbank2')
ctr=0
lux_id = 1
os.system('cp briefexp seriebrief_template')
os.system('cp briefexp seriebrief')
with con:
cur = con.cursor()
for lux_id in range(1, 5):
f = open('seriebrief', 'r+')
f.seek(-1,2)
string = str("\n\n\Adresse{\n\t")
for ctr in range(0, 5):
sql = "SELECT vorname, nachname, adresse, plz, ort FROM member WHERE id=%d" %(10 * lux_id)
cur.execute(sql)
rows = [ a[ctr] for a in cur.fetchall()]
for row in rows:
print row
string = string + str(row) + str(" ")
if ctr == 1:
string = string + str("\\\\\n")
if ctr == 2:
string = string + str("\\\\\n")
ctr = ctr + 1
string = string + str("}\n\n")
f.write(string)
f.close()
f = open('briefexp3', 'r')
string2 = f.read()
string = str(string2)
f.close()
f = open('seriebrief', 'r+')
f.seek(-1,2)
f.write(string)
f.close()
filenames = str("cp seriebrief seriebrief_%d.tex") % (lux_id)
os.system(filenames)
os.system('rm seriebrief')
os.system('cp seriebrief_template seriebrief')
lux_id = lux_id + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment