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/
donationcalc/__pycache__/
donors.txt
donationcalc/config.ini

View File

@ -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

View File

@ -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:

12
run.py
View File

@ -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)