diff --git a/app/database.py b/app/database.py index b2422d3..d452465 100644 --- a/app/database.py +++ b/app/database.py @@ -7,6 +7,7 @@ from consumption import Consumption from deposit import Deposit import random as rand import datetime +from settings import settings DATABASE = 'test/database.db' @@ -56,6 +57,7 @@ def get_user(u): u.isblack=row[6] u.isbaron=row[7] u.isshown=row[8] + u.autoblack=row[9] print u return u @@ -73,6 +75,7 @@ def get_user_by_name(name): u.isblack=row[6] u.isbaron=row[7] u.isshown=row[8] + u.autoblack=row[9] print u return u @@ -108,6 +111,7 @@ def get_users(): u.isblack=row[6] u.isbaron=row[7] u.isshown=row[8] + u.autoblack=row[9] users.append(u) return users @@ -119,7 +123,7 @@ def add_user(u): def update_user(u): #query_db("UPDATE users SET (NAME, LONGNAME, EMAIL, RFID_ID, ISBLACK, ISBARON, ISSHOWN) VALUES (?, ?, ?, ?, ?, ?, ?) WHERE ID=?", (u.name, u.longname, u.email, u.rfid_id, u.isblack, u.isbaron, u.isshown, u.id)) - query_db("UPDATE users SET NAME=?, LONGNAME=?, EMAIL=?, RFID_ID=?, ISBLACK=?, ISBARON=?, ISSHOWN=? WHERE ID=?", (u.name, u.longname, u.email, u.rfid_id, u.isblack, u.isbaron, u.isshown, u.id)) + query_db("UPDATE users SET NAME=?, LONGNAME=?, EMAIL=?, RFID_ID=?, ISBLACK=?, ISBARON=?, ISSHOWN=?, AUTOBLACK=? WHERE ID=?", (u.name, u.longname, u.email, u.rfid_id, u.isblack, u.isbaron, u.isshown, u.autoblack, u.id)) get_db().commit() @@ -199,6 +203,12 @@ def add_consume(username, productid): #INSERT INTO USERS (NAME, PASSWORD, LONGNAME, EMAIL, RFID_ID) VALUES (? ,? ,?, ?, ?)", (u.name, u.password, u.longname, u.email, u.rfid_id)) query_db("INSERT INTO CONSUMED (PRODNR, CONSUMER, PRICE, TIME) VALUES (?, ?, ?, ?)", (str(product.id), str(consumerid), product.price, datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))) get_db().commit() + + if settings.autoBlack: + if get_debt(name=username) > settings.blockLimit: + u = get_user_by_name(username) + u.isblack = True + update_user(u) print "consumed" return @@ -213,6 +223,8 @@ def get_debt(name=None): deposits = get_deposits(get_user_by_name(name).id) for deposit in deposits: debt -= deposit.amount + + debt = round(debt, 2) return debt @@ -234,6 +246,21 @@ def get_deposits(userid = None): deposits.append(d) return deposits +def add_deposit(username, amount): + consumerid = query_db("SELECT ID FROM USERS WHERE NAME = ?", [username], one=True) + consumerid = int(consumerid[0]) + query_db("INSERT INTO DEPOSITS (USERID, AMOUNT, TIME) VALUES (?, ?, ?)", (str(consumerid), amount, datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))) + get_db().commit() + if settings.autoUnblack: + if get_debt(name=username) < settings.blockLimit: + u = get_user_by_name(username) + u.isblack = False + update_user(u) + print "deposit" + + return + + ##for testing only def generate_test_users(): @@ -267,4 +294,4 @@ def add_test_consume(consumerid, productid, daysago): product = get_product_by_id(productid) query_db("INSERT INTO CONSUMED (PRODNR, CONSUMER, PRICE, TIME) VALUES (?, ?, ?, ?)", (str(product.id), str(consumerid), product.price, (datetime.datetime.now()-datetime.timedelta(days=daysago)).strftime("%Y-%m-%d %H:%M:%S"))) get_db().commit() - return \ No newline at end of file + return diff --git a/app/gui.py b/app/gui.py index 0caef94..5af9a9e 100644 --- a/app/gui.py +++ b/app/gui.py @@ -274,7 +274,7 @@ class PanelUsers (wx.Panel): self.but.SetBackgroundColour((255-(i*20 % 40), (160+(i*50 % 100)), 0)) #self.but.SetForegroundColour("#006699") - self.but.SetPressColor(wx.Color(255,255,255,0)) + self.but.SetPressColor(wx.Colour(255,255,255,0)) self.but.SetFont(wx.Font(25, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Humor Sans")) self.but.Bind(wx.EVT_LEFT_DOWN, parent.onUser, id=self.but.Id) self.but_names.append(self.but) diff --git a/app/send_email.py b/app/send_email.py new file mode 100644 index 0000000..fa1ae48 --- /dev/null +++ b/app/send_email.py @@ -0,0 +1,59 @@ +import smtplib +import database +# import email +# from email.mime.text import MIMEText +# from email.MIMEText import MIMEText +import user + +def send_email(recipient, subject, body): + gmail_user = 'bier1baroness' + gmail_pwd = 'test11test11' + FROM = 'bier1baroness@gmail.com' + SUBJECT = subject + TEXT = body + + # Prepare actual message + message = u"Content-Type: text/plain; charset=utf-8\nFrom: Baroness <%s>\nTo: %s\nSubject: %s\n\n%s" % (FROM, recipient, SUBJECT, TEXT) + message = message.encode('utf-8') + + # message = msg.as_string() + print message + try: + server = smtplib.SMTP("smtp.gmail.com:587") + #server.set_debuglevel(1) + server.starttls() + server.login(gmail_user, gmail_pwd) + server.sendmail(FROM, recipient, message) + server.quit() + print 'Mail was sent to %s' % recipient + + except: + print "Failed to send mail to %s" %recipient + +def send_emails(body, subject, users): + FROM = 'bier1baroness@gmail.com' + + for user in users: + debt = get_debt(user.name) + subject_parsed = parse_email(subject, user, debt) + body_parsed = parse_email(body, user, debt) + send_email(user.email, subject_parsed, body_parsed) + + + + +def parse_email(text, u, dept): + + text = text.replace('%%longname%%', u.longname) + text = text.replace('%%dept%%', str(dept)) + + if text.find('%%if_is_black%%', 0, text.__len__()): + start = text.find('%%if_is_black%%', 0, text.__len__()) + end = text.find('%%end_if_is_black%%') + + if not u.isblack: + text = text.replace(text[start:end], '') + text = text.replace('%%if_is_black%%', '') + text = text.replace('%%end_if_is_black%%', '') + + return text diff --git a/app/settings.py b/app/settings.py index 4200cc8..864cb2d 100644 --- a/app/settings.py +++ b/app/settings.py @@ -32,8 +32,8 @@ class Settings: ##Payment Incentives #Money Limit - self.autoBlock = False #Automatically block user if money owed > limit - self.autoUnblock = False #Automatically unblock user if money owed < limit + self.autoBlack = True #Automatically block user if money owed > limit + self.autoUnblack = True #Automatically unblock user if money owed < limit self.blockLimit = 150 #Money limit for automatic blocking (default 150) #Mail Spam self.autoAnnoy = False #Automatically send payment eMails diff --git a/app/templates/billing.html b/app/templates/billing.html index 248c1d7..4fed4f7 100644 --- a/app/templates/billing.html +++ b/app/templates/billing.html @@ -5,11 +5,13 @@
{{ success }}
{% endif %}An alle User Rechnungen versenden.
-An alle User Rechnungen versenden.
{% endblock %} \ No newline at end of file diff --git a/app/templates/billing_mass_mail.html b/app/templates/billing_mass_mail.html index 8605953..99dc2ed 100644 --- a/app/templates/billing_mass_mail.html +++ b/app/templates/billing_mass_mail.html @@ -1,23 +1,34 @@ {% extends "base.html"%} -{% set title = "An alle User Rechnung versenden" %} +{% set title = "An alle User Rechnungen versenden" %} {% block content %}{{ success }}
{% endif %}Der text den du eingibst wird von der Baroness noch personalisiert. Folgende Komandos kennt die Baroness.
+An alle User Rechnungen versenden.
+ {% endblock %} \ No newline at end of file diff --git a/app/templates/manage_users.html b/app/templates/manage_users.html index ce7f793..5316382 100644 --- a/app/templates/manage_users.html +++ b/app/templates/manage_users.html @@ -12,6 +12,7 @@