diff --git a/.gitignore b/.gitignore index f7275bb..85219c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ venv/ +donationcalc/__pycache__/ +donors.txt +donationcalc/config.ini diff --git a/donationcalc/config.ini b/donationcalc/config.ini index 1f9167b..96ea11a 100644 --- a/donationcalc/config.ini +++ b/donationcalc/config.ini @@ -1,10 +1,10 @@ [credentials] -smtphost = 'mail.example.org' +smtphost = mail.example.org smtpport = 587 smtpstarttls = True -smtpusername = 'donations' -smtppassword = 'verysecr3t' -smtpaddress = 'donations@example.org' +smtpusername = donations +smtppassword = verysecr3t +smtpaddress = donations@example.org [finance] currency = EUR diff --git a/donationcalc/models.py b/donationcalc/models.py index c508602..1932024 100644 --- a/donationcalc/models.py +++ b/donationcalc/models.py @@ -1,7 +1,7 @@ import smtplib from . import donationconfig -def sendmail(donor, subject, messsage): +def sendmail(donor, subject, message): ''' Sending mail to email of given donor with given subject and message ''' @@ -13,7 +13,7 @@ def sendmail(donor, subject, messsage): smtpcon.login(str(config.smtpusername), str(config.smtppassword)) - smtpcon.sendmail(config.smtpaddress, donor.email, f"From: {config.smtpaddress}\r\nTo: {mail_to}\r\nSubject: {subject}\r\n\r\n{message}") + smtpcon.sendmail(config.smtpaddress, donor.email, f"From: {config.smtpaddress}\r\nTo: {donor.email}\r\nSubject: {subject}\r\n\r\n{message}") return 0 @@ -24,7 +24,7 @@ def rebalanceall(sender, donors = []): sender.monthlyrebalance(donors) for donor in donors: - donor.monthlyrebalance(sender) + donor.monthlyrebalance() return 0 @@ -39,23 +39,25 @@ class sender(): def __init__(self, balance = 'notset', monthlycost = 'notset'): - if balance != 'notset': - self.balance = config.balance - else: - self.balance = balance + config = donationconfig.donationconfig() - if monthlycost != 'notset': - self.monthlycost = config.monthlycost + if balance == 'notset': + self.balance = int(config.balance) else: - self.monthlycost = monthlycost + self.balance = int(balance) + + if monthlycost == 'notset': + self.monthlycost = int(config.monthlycost) + else: + self.monthlycost = int(monthlycost) def monthlyrebalance(self, donors = []): - newbalance = self.balance - self.monthlycost + newbalance = int(self.balance) - int(self.monthlycost) self.balance = newbalance if newbalance - self.monthlycost < 0: - sendtoall(donors) + self.sendtoall(donors) return -1 else: return 0 @@ -88,7 +90,7 @@ class donor(): self.balance = 0 def monthlyrebalance(self): - newbalance = self.balance - self.monthly + newbalance = int(self.balance) - int(self.monthly) self.balance = newbalance if newbalance < 0: diff --git a/run.py b/run.py index b32394a..edb5892 100755 --- a/run.py +++ b/run.py @@ -1,5 +1,6 @@ from donationcalc import app from donationcalc import donationconfig +import donationcalc.models import argparse def parseArgs(parser): @@ -14,6 +15,17 @@ if __name__ == '__main__': if args.rebalance: donconf = donationconfig.donationconfig() donconf.rebalance() + sender = donationcalc.models.sender() + donors = [] + f = open("donors.txt", "r") + + for line in f.readlines(): + linesplit = line.split(",") + newdonor = donationcalc.models.donor(email = linesplit[0], monthly = linesplit[1]) + donors.append(newdonor) + f.close() + + donationcalc.models.rebalanceall(sender,donors) exit() app.run(debug=False)