forked from github/server
automatic patching before reset of waiting list
This commit is contained in:
parent
563600412d
commit
1bcb3ec339
|
@ -15,6 +15,6 @@ if num>maxnum:
|
|||
while num:
|
||||
num=num-1
|
||||
email, race, locale, bonus = cursor.fetchone()
|
||||
if bonus=None:
|
||||
bonus=1
|
||||
if bonus==None:
|
||||
bonus=0
|
||||
print email+" "+race+" "+locale+" "+str(int(bonus))
|
||||
|
|
|
@ -5,33 +5,15 @@ import sys
|
|||
import smtplib
|
||||
|
||||
From='accounts@vinyambar.de'
|
||||
dbname=sys.argv[1]
|
||||
userid=sys.argv[2]
|
||||
#!/usr/bin/env python
|
||||
|
||||
db=MySQLdb.connect(db=dbname)
|
||||
import re
|
||||
import MySQLdb
|
||||
import sys
|
||||
|
||||
def pay(db, userid, email, cash, date, reason='PAYMENT'):
|
||||
cursor=db.cursor()
|
||||
locale="de"
|
||||
|
||||
i=cursor.execute('SELECT email, firstname, lastname FROM users, transactions WHERE users.id='+str(userid))
|
||||
|
||||
if i==0:
|
||||
print "Unknown user "+str(userid)
|
||||
sys.exit()
|
||||
|
||||
email, firstname, lastname = cursor.fetchone()
|
||||
i=cursor.execute('SELECT sum(balance) from transactions WHERE user='+str(userid))
|
||||
balance=cursor.fetchone()[0]
|
||||
if balance==None:
|
||||
balance=0.0
|
||||
print 'Balance for '+firstname+' '+lastname+' is '+str(balance)+' EUR'
|
||||
|
||||
if len(sys.argv)>4:
|
||||
cash=float(sys.argv[3])
|
||||
date=sys.argv[4]
|
||||
reason='PAYMENT'
|
||||
if len(sys.argv)>5:
|
||||
reason=sys.argv[5]
|
||||
|
||||
cursor.execute("UPDATE users SET status='PAYING' WHERE id="+str(userid));
|
||||
|
||||
cursor.execute('INSERT transactions (user, balance, description, date) VALUES ('+str(userid)+', '+str(cash)+', \''+reason+'\', \''+date+'\')')
|
||||
|
@ -41,7 +23,10 @@ if len(sys.argv)>4:
|
|||
if result!=0:
|
||||
reason = cursor.fetchone()[0]
|
||||
|
||||
print 'Transaction #'+str(lastid)+', new balance is '+str(balance+cash)
|
||||
i=cursor.execute('SELECT sum(balance) from transactions WHERE user='+str(userid))
|
||||
balance=cursor.fetchone()[0]
|
||||
if balance==None:
|
||||
balance=0.0
|
||||
|
||||
Msg = ("From: Vinyambar Buchhaltung <"+From+">\nTo: "+email+"\nSubject: Vinyambar Zahlungseingang.\n\n"+
|
||||
"Kundennummer: "+str(userid)+"\n"+
|
||||
|
@ -60,8 +45,114 @@ if len(sys.argv)>4:
|
|||
except:
|
||||
print "Could not send confirmation to "+email
|
||||
print "Exception is:", sys.exc_type, ":", sys.exc_value
|
||||
return
|
||||
|
||||
cursor.execute("select sum(transactions.balance) from transactions")
|
||||
def charge(ids, balance, kto, blz, date):
|
||||
if len(ids):
|
||||
custids = []
|
||||
db=MySQLdb.connect(db=dbname)
|
||||
cursor = db.cursor()
|
||||
for custid in ids:
|
||||
k = cursor.execute('SELECT firstname, lastname FROM users WHERE id='+str(custid))
|
||||
if k:
|
||||
custids.append(custid)
|
||||
if len(custids)==1:
|
||||
k = cursor.execute('SELECT balance from transactions where USER='+str(custid)+" and description='PAYMENT' and date='"+date+"'")
|
||||
if k:
|
||||
print "user already had a transaction today, not adding it for safety reasons"
|
||||
else:
|
||||
cursor.execute('SELECT email FROM users WHERE users.id='+str(custid))
|
||||
email = cursor.fetchone()[0]
|
||||
pay(db, custid, email, balance, date)
|
||||
return 0
|
||||
else:
|
||||
print "zero or more than one possible customerid found:", custids
|
||||
return -1
|
||||
|
||||
def eumel(dbname):
|
||||
balance=None
|
||||
kto=None
|
||||
blz=None
|
||||
date=None
|
||||
zweck=[]
|
||||
ids = []
|
||||
rv=0
|
||||
for line in sys.stdin.readlines():
|
||||
match=re.match('Buchung/Wert.* / ([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9]).*H (.*),(.*) EUR', line)
|
||||
if match!=None:
|
||||
if (balance!=None):
|
||||
r = charge(ids, balance, kto, blz, date)
|
||||
if r!=0:
|
||||
print "FAILED", balance, kto, blz, date, zweck
|
||||
rv=r
|
||||
balance=None
|
||||
kto=None
|
||||
blz=None
|
||||
date=None
|
||||
ids = []
|
||||
date=match.groups()[0]+'-'+match.groups()[1]+'-'+match.groups()[2]
|
||||
balance=float(match.groups()[3]+'.'+match.groups()[4])
|
||||
continue
|
||||
match=re.match(' KTO/BLZ\s*([0-9]*) / ([0-9]*)', line)
|
||||
if match!=None:
|
||||
kto, blz = match.groups()
|
||||
continue
|
||||
match=re.match(' VZweck [0-9] *(.*)', line)
|
||||
if match!=None:
|
||||
zweck.append(line)
|
||||
line=match.groups()[0]
|
||||
while len(line):
|
||||
match = re.match('(.*[^ ]) +(.+)', line)
|
||||
if (match!=None):
|
||||
line, value = match.groups()
|
||||
else:
|
||||
value = line
|
||||
line=''
|
||||
try:
|
||||
custid = int(value)
|
||||
ids.append(custid)
|
||||
except ValueError:
|
||||
continue
|
||||
if (balance):
|
||||
r = charge(ids, balance, kto, blz, date)
|
||||
if r!=0:
|
||||
print "FAILED", balance, kto, blz, date, zweck
|
||||
rv=r
|
||||
return rv
|
||||
|
||||
def manual(dbname):
|
||||
userid=sys.argv[2]
|
||||
|
||||
db=MySQLdb.connect(db=dbname)
|
||||
cursor=db.cursor()
|
||||
|
||||
i=cursor.execute('SELECT email, firstname, lastname FROM users, transactions WHERE users.id='+str(userid))
|
||||
if i==0:
|
||||
print "Unknown user "+str(userid)
|
||||
sys.exit()
|
||||
|
||||
email, firstname, lastname = cursor.fetchone()
|
||||
i=cursor.execute('SELECT sum(balance) from transactions WHERE user='+str(userid))
|
||||
balance=cursor.fetchone()[0]
|
||||
print str(balance)+ " EUR (" + str(balance*1.955830)+ " DEM)"
|
||||
if balance==None:
|
||||
balance=0.0
|
||||
|
||||
print 'Balance for '+firstname+' '+lastname+' is '+str(balance)+' EUR'
|
||||
|
||||
if len(sys.argv)>4:
|
||||
cash=float(sys.argv[3])
|
||||
date=sys.argv[4]
|
||||
reason='PAYMENT'
|
||||
if len(sys.argv)>5:
|
||||
reason=sys.argv[5]
|
||||
|
||||
pay(db, int(userid), email, balance, date, reason)
|
||||
print 'New balance is '+str(balance+cash)+' EUR'
|
||||
return
|
||||
|
||||
dbname=sys.argv[1]
|
||||
if sys.argv[2]=='--eumel':
|
||||
r = eumel(dbname)
|
||||
sys.exit(r)
|
||||
else:
|
||||
manual(dbname)
|
||||
|
|
|
@ -15,11 +15,23 @@ import smtplib
|
|||
dbname=sys.argv[1]
|
||||
date=sys.argv[2]
|
||||
db=MySQLdb.connect(db=dbname)
|
||||
From='accounts@eressea-pbem.de'
|
||||
cursor=db.cursor()
|
||||
From='accounts@eressea-pbem.de'
|
||||
MailTemplate="templates/register.mail"
|
||||
smtpserver='localhost'
|
||||
server=smtplib.SMTP(smtpserver)
|
||||
patchdir='/home/eressea/eressea-rsync'
|
||||
|
||||
def Patch():
|
||||
i = cursor.execute("select name, patch from games where id=0")
|
||||
name, patch = cursor.fetchone()
|
||||
print "Auswertung für " + name + " Patch Level " + str(int(patch)) + ", Runde "+str(lastturn)
|
||||
while os.access(patchdir+'/patch-'+str(int(patch+1))+'.sql', os.F_OK):
|
||||
patch=patch+1
|
||||
print " Patching to level "+str(patch)
|
||||
os.system('mysql ' + dbname + ' < ' + patchdir+'/patch-'+str(int(patch))+'.sql')
|
||||
cursor.execute('update games set patch='+str(int(patch))+' where id='+str(gid))
|
||||
return
|
||||
|
||||
def Send(email, custid, firstname, password, position, locale):
|
||||
TemplateHandle = open(MailTemplate+"."+locale, "r") # open in read only mode
|
||||
|
@ -37,6 +49,7 @@ def Send(email, custid, firstname, password, position, locale):
|
|||
server.sendmail(From, email, Msg)
|
||||
return
|
||||
|
||||
Patch()
|
||||
cursor.execute("update users set status='EXPIRED' where TO_DAYS(updated)<TO_DAYS('"+date+"') and status='WAITING'")
|
||||
cursor.execute("update users set status='WAITING' where TO_DAYS(updated)<TO_DAYS('"+date+"') and status='CONFIRMED'")
|
||||
users = cursor.execute("select firstname, locale, email, id, password from users where status='WAITING' order by id")
|
||||
|
|
|
@ -30,7 +30,7 @@ while users > 0:
|
|||
Msg=None
|
||||
if balance <= games*warnahead*price:
|
||||
Msg = ("From: Vinyambar Buchhaltung <"+From+">\nTo: "+email+"\n")
|
||||
if balance <= -games*cancelafter*price:
|
||||
if balance < -games*cancelafter*price:
|
||||
Msg=Msg+"Subject: Vinyambar Abmeldung Kunde "+str(int(uid))+".\n\n"
|
||||
Msg = Msg+("Nachdem Dein Konto bei uns im Minus ist, haben wir deine\n"+
|
||||
"Anmeldung bei Vinyambar gekündigt, und die Partei(en) der Parteibörse\n"+
|
||||
|
|
Loading…
Reference in New Issue