From b68713a18bcc02509348753f271f2411d9b0f8bd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 7 Apr 2002 11:42:27 +0000 Subject: [PATCH] updated zat script --- scripts/register/confirm.py | 16 ++++++++++------ scripts/register/zat.py | 38 ++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/scripts/register/confirm.py b/scripts/register/confirm.py index 90d8a47ad..bd7786cb3 100755 --- a/scripts/register/confirm.py +++ b/scripts/register/confirm.py @@ -1,5 +1,10 @@ #!/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 MySQLdb import smtplib @@ -39,14 +44,13 @@ while records>0: " http://www.vinyambar.de/accounts.shtml\n"+ "\n"+ "Das Vinyambar-Team") + now = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()) try: server.sendmail(From, email, Msg) - print "Sent confirmation to "+email+"." + print "[%s] USER %d - UPDATE: status='WAITING' " % (now, customerid) update=db.cursor() - update.execute("UPDATE users set status='CONFIRMED' WHERE id="+ - str(int(customerid))); + update.execute("UPDATE users set status='WAITING' WHERE id="+ + str(int(customerid))) except: - print "Could not send Error to "+email - print "Reason was: '"+Reason+"'" - print "Exception is:", sys.exc_type, ":", sys.exc_value + print "[%s] USER %d - ERROR: could not send to %s: %s " % (now, customerid, email, sys.exc_indo()) sys.exit() diff --git a/scripts/register/zat.py b/scripts/register/zat.py index 958498f28..d6418f89c 100755 --- a/scripts/register/zat.py +++ b/scripts/register/zat.py @@ -4,15 +4,24 @@ import sys import os dbname=sys.argv[1] -game=int(sys.argv[2]) +gid=int(sys.argv[2]) date=sys.argv[3] price=1.25 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() -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: print "Unbekanntes Spiel" @@ -28,28 +37,27 @@ 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(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+"'") -if k: - print "Removing untransfered subscriptions." +k = cursor.execute("select user, faction from subscriptions where game="+str(gid)+" and status='TRANSFERED' and updated<'"+date+"'") +print "Removing "+str(int(k))+" transfered 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+"'") -if k: - print "Removing cancelled subscriptions." +k = cursor.execute("select user, faction from subscriptions where game="+str(gid)+" and status='CANCELLED' and updated<'"+date+"'") +print "Removing "+str(int(k))+" cancelled subscriptions." +SetUser(cursor, int(k), 0) -k = cursor.execute("UPDATE subscriptions SET user=0 where game="+str(int(game))+" and status='DEAD'") -if k: - print "Removing dead subscriptions." +k = cursor.execute("select user, faction from subscriptions where game="+str(gid)+" and status='DEAD'") +print "Removing "+str(int(k))+" dead subscriptions." k = cursor.execute("UPDATE subscriptions SET status='CANCELLED' where game="+str(int(game))+" and status='ACTIVE' and lastturn+3<="+str(lastturn)) if k: 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: k=k-1 user = int(cursor.fetchone()[0]) 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)+"')")