2002-02-05 00:44:14 +01:00
#!/usr/bin/env python
import MySQLdb
import sys
import smtplib
From = ' accounts@vinyambar.de '
dbname = sys . argv [ 1 ]
2002-03-17 18:19:10 +01:00
dryrun = 0
if len ( sys . argv ) > 2 :
dryrun = 1
2002-02-05 00:44:14 +01:00
price = 1.25
warnahead = 2
db = MySQLdb . connect ( db = dbname )
cursor = db . cursor ( )
2002-03-24 15:29:35 +01:00
users = cursor . execute ( " select users.email, users.id, count(subscriptions.game) from users, subscriptions, games where users.id=subscriptions.user and subscriptions.game=games.id and users.id!=0 and games.status= ' RUNNING ' GROUP BY users.id " )
2002-02-05 00:44:14 +01:00
server = smtplib . SMTP ( ' localhost ' )
while users > 0 :
users = users - 1
email , uid , games = cursor . fetchone ( )
c2 = db . cursor ( )
t = c2 . execute ( " select sum(balance) from transactions where user= " + str ( int ( uid ) ) )
if t == 0 :
balance = 0.0
else :
balance = c2 . fetchone ( ) [ 0 ]
if balance < games * warnahead * price :
print " Warning " + email + " , uid= " + str ( int ( uid ) ) + " , balance= " + str ( balance ) + " , games= " + str ( int ( games ) )
Msg = ( " From: Vinyambar Buchhaltung < " + From + " > \n To: " + email + " \n Subject: Vinyambar Kontostand, Warnung. \n \n " +
" Dein Vinyambar Kontostand reicht nicht mehr aus, um die kommenden " + str ( warnahead ) + " \n " +
" Wochen zu bezahlen. Bitte mache baldm<64> glichst eine neue <20> berweisung \n "
" auf das Vinyambar-Konto. \n \n " +
" Kundennummer: " + str ( uid ) + " \n " +
" Kontostand: " + str ( balance ) + " EUR \n " +
" \n " +
" Unser Konto: Katja Zedel \n " +
" Kontonummer 1251 886 106 \n " +
" BLZ 500 502 01 (Frankfurter Sparkasse) \n " )
try :
# print Msg
2002-03-17 18:19:10 +01:00
if dryrun == 0 :
server . sendmail ( From , email , Msg )
2002-02-05 00:44:14 +01:00
except :
print " Could not send confirmation to " + email
print " Exception is: " , sys . exc_type , " : " , sys . exc_value