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
# 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()

View File

@ -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)+"')")