fix email and remove qoutes from conf

This commit is contained in:
fram3d 2023-07-13 17:50:33 +02:00
parent 8d2fb79d06
commit 8be400a721
Signed by: fram3d
GPG Key ID: 938920E709EEA32A
4 changed files with 34 additions and 17 deletions

3
.gitignore vendored
View File

@ -1 +1,4 @@
venv/ venv/
donationcalc/__pycache__/
donors.txt
donationcalc/config.ini

View File

@ -1,10 +1,10 @@
[credentials] [credentials]
smtphost = 'mail.example.org' smtphost = mail.example.org
smtpport = 587 smtpport = 587
smtpstarttls = True smtpstarttls = True
smtpusername = 'donations' smtpusername = donations
smtppassword = 'verysecr3t' smtppassword = verysecr3t
smtpaddress = 'donations@example.org' smtpaddress = donations@example.org
[finance] [finance]
currency = EUR currency = EUR

View File

@ -1,7 +1,7 @@
import smtplib import smtplib
from . import donationconfig 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 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.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 return 0
@ -24,7 +24,7 @@ def rebalanceall(sender, donors = []):
sender.monthlyrebalance(donors) sender.monthlyrebalance(donors)
for donor in donors: for donor in donors:
donor.monthlyrebalance(sender) donor.monthlyrebalance()
return 0 return 0
@ -39,23 +39,25 @@ class sender():
def __init__(self, balance = 'notset', monthlycost = 'notset'): def __init__(self, balance = 'notset', monthlycost = 'notset'):
if balance != 'notset': config = donationconfig.donationconfig()
self.balance = config.balance
else:
self.balance = balance
if monthlycost != 'notset': if balance == 'notset':
self.monthlycost = config.monthlycost self.balance = int(config.balance)
else: 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 = []): def monthlyrebalance(self, donors = []):
newbalance = self.balance - self.monthlycost newbalance = int(self.balance) - int(self.monthlycost)
self.balance = newbalance self.balance = newbalance
if newbalance - self.monthlycost < 0: if newbalance - self.monthlycost < 0:
sendtoall(donors) self.sendtoall(donors)
return -1 return -1
else: else:
return 0 return 0
@ -88,7 +90,7 @@ class donor():
self.balance = 0 self.balance = 0
def monthlyrebalance(self): def monthlyrebalance(self):
newbalance = self.balance - self.monthly newbalance = int(self.balance) - int(self.monthly)
self.balance = newbalance self.balance = newbalance
if newbalance < 0: if newbalance < 0:

12
run.py
View File

@ -1,5 +1,6 @@
from donationcalc import app from donationcalc import app
from donationcalc import donationconfig from donationcalc import donationconfig
import donationcalc.models
import argparse import argparse
def parseArgs(parser): def parseArgs(parser):
@ -14,6 +15,17 @@ if __name__ == '__main__':
if args.rebalance: if args.rebalance:
donconf = donationconfig.donationconfig() donconf = donationconfig.donationconfig()
donconf.rebalance() 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() exit()
app.run(debug=False) app.run(debug=False)