2002-03-24 15:29:35 +01:00
#!/usr/bin/env python
#
# reset the waiting list after ZAT.
# before running this script, be sure to apply the patchfile generated by the eressea-server to
# mark users with new accounts as ACTIVE.
# * Will mark WAITING users as EXPIRED, removig them from the waitng list.
# * Will mark CONFIRMED users as WAITING, and send them another mail.
import MySQLdb
2002-04-29 16:53:41 +02:00
import string
2002-03-24 15:29:35 +01:00
import re
import sys
2002-04-29 16:53:41 +02:00
import os
2002-03-24 15:29:35 +01:00
import smtplib
dbname = sys . argv [ 1 ]
date = sys . argv [ 2 ]
2002-04-15 20:57:16 +02:00
From = ' accounts@eressea-pbem.de '
2002-03-24 15:29:35 +01:00
smtpserver = ' localhost '
server = smtplib . SMTP ( smtpserver )
2002-04-15 20:57:16 +02:00
patchdir = ' /home/eressea/eressea-rsync '
2002-04-21 14:09:21 +02:00
game_id = 0
2002-04-15 20:57:16 +02:00
2002-04-29 16:53:41 +02:00
db = MySQLdb . connect ( db = dbname )
cursor = db . cursor ( )
cursor . execute ( " select name, patch from games where id= " + str ( game_id ) )
game , patch = cursor . fetchone ( )
MailTemplate = " templates/register.mail. " + string . lower ( game )
2002-04-15 20:57:16 +02:00
def Patch ( ) :
2002-04-29 16:53:41 +02:00
global patch
print " Auswertung f<> r " + game + " Patch Level " + str ( int ( patch ) )
2002-04-15 20:57:16 +02:00
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 ' )
2002-04-29 16:53:41 +02:00
cursor . execute ( ' update games set patch= ' + str ( int ( patch ) ) + ' where id= ' + str ( game_id ) )
2002-04-15 20:57:16 +02:00
return
2002-03-24 15:29:35 +01:00
def Send ( email , custid , firstname , password , position , locale ) :
TemplateHandle = open ( MailTemplate + " . " + locale , " r " ) # open in read only mode
# read the entire file as a string
TemplateInput = TemplateHandle . read ( )
TemplateHandle . close ( ) # close the file
SubResult = re . subn ( " <FIRSTNAME> " , firstname , TemplateInput )
2002-05-01 17:23:43 +02:00
SubResult = re . subn ( " <GAME> " , game , SubResult [ 0 ] )
2002-03-24 15:29:35 +01:00
SubResult = re . subn ( " <PASSWORD> " , password , SubResult [ 0 ] )
SubResult = re . subn ( " <POSITION> " , str ( int ( position ) ) , SubResult [ 0 ] )
SubResult = re . subn ( " <CUSTID> " , str ( int ( custid ) ) , SubResult [ 0 ] )
Msg = " From: " + From + " \n To: " + email + " \n Subject: Eressea Anmeldung \n \n "
Msg = Msg + SubResult [ 0 ]
server . sendmail ( From , email , Msg )
return
2002-04-15 20:57:16 +02:00
Patch ( )
2002-04-21 14:09:21 +02:00
# remove all illegal and banned users:
users = cursor . execute ( " SELECT s.id from users u, subscriptions s where u.id=s.user and u.status in ( ' BANNED ' , ' ILLEGAL ' ) " )
2002-04-29 16:53:41 +02:00
update = db . cursor ( )
2002-03-24 15:29:35 +01:00
while users :
users = users - 1
2002-04-21 14:09:21 +02:00
sid = cursor . fetchone ( ) [ 0 ]
update . execute ( " UPDATE subscriptions set status= ' EXPIRED ' WHERE id= " + str ( int ( sid ) ) )
# espire all users without confirmation. reset waiting list.
cursor . execute ( " update subscriptions set status= ' EXPIRED ' where TO_DAYS(updated)<TO_DAYS( ' " + date + " ' ) and status= ' WAITING ' " )
cursor . execute ( " update subscriptions set status= ' WAITING ' where TO_DAYS(updated)<TO_DAYS( ' " + date + " ' ) and status= ' CONFIRMED ' " )
# remind everyone who is left on the waiting list.
2002-05-01 17:23:43 +02:00
waiting = cursor . execute ( " select firstname, locale, email, u.id, s.password, u.password from users u, subscriptions s where u.id=s.user and s.status= ' WAITING ' ORDER BY s.id " )
2002-04-21 14:09:21 +02:00
position = 0
while waiting :
waiting = waiting - 1
2002-03-24 15:29:35 +01:00
position = position + 1
2002-04-29 16:53:41 +02:00
firstname , locale , email , custid , password , altpass = cursor . fetchone ( )
if password == None :
password = altpass
2002-03-24 15:29:35 +01:00
print " Sending reminder email to " + str ( int ( custid ) ) + " " + email
Send ( email , custid , firstname , password , position , locale )
server . close ( )