updated zat script

This commit is contained in:
Enno Rehling 2002-04-07 11:42:27 +00:00
parent 53d6ed81d1
commit b68713a18b
2 changed files with 33 additions and 21 deletions

View File

@ -1,5 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
# this script picks all NEW users from the database, (subscribed through
# the web interface), and sends them their customer-id and password
# if the mail was sent cuccessfully, it sets the user to the 'WAITING'
# state, meaning that we wait for his confirmation.
import sys import sys
import MySQLdb import MySQLdb
import smtplib import smtplib
@ -39,14 +44,13 @@ while records>0:
" http://www.vinyambar.de/accounts.shtml\n"+ " http://www.vinyambar.de/accounts.shtml\n"+
"\n"+ "\n"+
"Das Vinyambar-Team") "Das Vinyambar-Team")
now = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
try: try:
server.sendmail(From, email, Msg) server.sendmail(From, email, Msg)
print "Sent confirmation to "+email+"." print "[%s] USER %d - UPDATE: status='WAITING' " % (now, customerid)
update=db.cursor() update=db.cursor()
update.execute("UPDATE users set status='CONFIRMED' WHERE id="+ update.execute("UPDATE users set status='WAITING' WHERE id="+
str(int(customerid))); str(int(customerid)))
except: except:
print "Could not send Error to "+email print "[%s] USER %d - ERROR: could not send to %s: %s " % (now, customerid, email, sys.exc_indo())
print "Reason was: '"+Reason+"'"
print "Exception is:", sys.exc_type, ":", sys.exc_value
sys.exit() sys.exit()

View File

@ -4,15 +4,24 @@ import sys
import os import os
dbname=sys.argv[1] dbname=sys.argv[1]
game=int(sys.argv[2]) gid=int(sys.argv[2])
date=sys.argv[3] date=sys.argv[3]
price=1.25 price=1.25
db=MySQLdb.connect(db=dbname) db=MySQLdb.connect(db=dbname)
patchdir='/home/eressea/vinyambar-rsync/vin'+str(game)+'/data' patchdir='/home/eressea/vinyambar-rsync/vin'+str(gid)+'/data'
cursor=db.cursor() cursor=db.cursor()
k = cursor.execute('select name, patch from games where id='+str(game)) def SetUser(cursor, num, newuser):
update = db.cursor()
while num:
num = num-1
uid, faction = cursor.fetchone()
update.execute("insert into transfers (faction, game, src,dst) values ('"+faction+"', "+str(gid)+", "+str(int(uid))+", 0)")
update.execute("update subscriptions set user="+str(newuser)+" where game="+str(gid)+" and faction='"+faction+"'")
k = cursor.execute('select name, patch from games where id='+str(gid))
if k==0: if k==0:
print "Unbekanntes Spiel" print "Unbekanntes Spiel"
@ -28,28 +37,27 @@ while os.access(patchdir+'/patch-'+str(int(patch+1))+'.sql', os.F_OK):
patch=patch+1 patch=patch+1
print " Patching to level "+str(patch) print " Patching to level "+str(patch)
os.system('mysql ' + dbname + ' < ' + patchdir+'/patch-'+str(int(patch))+'.sql') os.system('mysql ' + dbname + ' < ' + patchdir+'/patch-'+str(int(patch))+'.sql')
cursor.execute('update games set patch='+str(int(patch))+' where id='+str(game)) cursor.execute('update games set patch='+str(int(patch))+' where id='+str(gid))
k = cursor.execute("UPDATE subscriptions SET user=0, status='CANCELLED' where game="+str(int(game))+" and status='TRANSFERED' and updated<'"+date+"'") k = cursor.execute("select user, faction from subscriptions where game="+str(gid)+" and status='TRANSFERED' and updated<'"+date+"'")
if k: print "Removing "+str(int(k))+" transfered subscriptions."
print "Removing untransfered subscriptions." SetUser(cursor, int(k), 0)
k = cursor.execute("UPDATE subscriptions SET user=0 where game="+str(int(game))+" and status='CANCELLED' and updated<'"+date+"'") k = cursor.execute("select user, faction from subscriptions where game="+str(gid)+" and status='CANCELLED' and updated<'"+date+"'")
if k: print "Removing "+str(int(k))+" cancelled subscriptions."
print "Removing cancelled subscriptions." SetUser(cursor, int(k), 0)
k = cursor.execute("UPDATE subscriptions SET user=0 where game="+str(int(game))+" and status='DEAD'") k = cursor.execute("select user, faction from subscriptions where game="+str(gid)+" and status='DEAD'")
if k: print "Removing "+str(int(k))+" dead subscriptions."
print "Removing dead subscriptions."
k = cursor.execute("UPDATE subscriptions SET status='CANCELLED' where game="+str(int(game))+" and status='ACTIVE' and lastturn+3<="+str(lastturn)) k = cursor.execute("UPDATE subscriptions SET status='CANCELLED' where game="+str(int(game))+" and status='ACTIVE' and lastturn+3<="+str(lastturn))
if k: if k:
print "Cancelling subscriptions with 3+ NMRs." print "Cancelling subscriptions with 3+ NMRs."
k = cursor.execute("SELECT users.id FROM users, subscriptions WHERE users.id=subscriptions.user and subscriptions.status='ACTIVE' and subscriptions.game="+str(game)) k = cursor.execute("SELECT users.id FROM users, subscriptions WHERE users.id=subscriptions.user and subscriptions.status='ACTIVE' and subscriptions.game="+str(gid))
while k!=0: while k!=0:
k=k-1 k=k-1
user = int(cursor.fetchone()[0]) user = int(cursor.fetchone()[0])
update=db.cursor() update=db.cursor()
update.execute("INSERT INTO transactions (user,date,balance,description) VALUES ("+str(user)+", '"+date+"', -"+str(price)+", 'ZAT-"+str(game)+"')") update.execute("INSERT INTO transactions (user,date,balance,description) VALUES ("+str(user)+", '"+date+"', -"+str(price)+", 'ZAT-"+str(gid)+"')")