diff --git a/wichteln.py b/wichteln.py index 64a2d6d..bf84640 100755 --- a/wichteln.py +++ b/wichteln.py @@ -31,7 +31,7 @@ args = parser.parse_args() # load and prepare a list containing all participants with open(args.pFileLocation, 'r') as pFile: - participants = json.load(pFile) + participants = json.load(pFile) # create a copy of the list to make choosing a partner easier copy = list(enumerate(participants[:])) @@ -39,32 +39,33 @@ copy = list(enumerate(participants[:])) # choose a partner for each participant for i in range(len(participants)): - # if the last participant has only themselves left to choose, make them - # switch partners with another random participant - if len(copy) == 1 and participants[i] == copy[0][1]: + # if the last participant has only themselves left to choose, make them + # switch partners with another random participant + if len(copy) == 1 and participants[i] == copy[0][1]: - current = participants[i] - participants.remove(current) - partner = random.choice(participants) + current = participants[i] + participants.remove(current) + partner = random.choice(participants) - current['partner'] = partner['partner'] - partner['partner'] = current['name'] + ' (' + current['mail']+')' - participants.append(current) - break + current['partner'] = partner['partner'] + partner['partner'] = current['name'] + ' (' + current['mail']+')' + participants.append(current) + break - # otherwise choose a random partner for each participant - else: - partner = random.choice(copy) - while partner[0] == i: - partner = random.choice(copy) + # otherwise choose a random partner for each participant + else: + partner = random.choice(copy) + while partner[0] == i: + partner = random.choice(copy) - participants[i]['partner'] = partner[1]['name']+' ('+partner[1]['mail']+')' - copy.remove(partner) + participants[i]['partner'] = partner[1]['name'] + \ + ' ('+partner[1]['mail']+')' + copy.remove(partner) # load mail server configuration and open smtp server connection with open(args.cFileLocation, 'r') as cFile: - config = json.load(cFile) - + config = json.load(cFile) + server = smtplib.SMTP(config['server'], config['port']) server.ehlo() server.starttls() @@ -74,36 +75,36 @@ server.login(config['user'], config['pass']) # create emails for all participants and send them # change the text for the mail here if you want to for r in participants: - - msg = MIMEMultipart('alternative') - msg['From'] = config['sender'] - msg['To'] = r['mail'] - msg['Subject'] = 'Wichteln 🎄' - msg['Message-ID'] = make_msgid(domain=config['sender'] - .split('@')[1] - .strip('>')) - msg['Date'] = formatdate(localtime=True) - - body = 'Lieb'+r['gender']+' '+r['name']+'!\n\n' - body += 'Du bist heuer Wichtel für '+r['partner']+'.\n' - body += 'Das Geschenk sollte nicht mehr als 50€ kosten.\n\n' - body += 'Frohe Weihnachten!\n— Dein Christkind 👼' - html = f""" + msg = MIMEMultipart('alternative') + msg['From'] = config['sender'] + msg['To'] = r['mail'] + msg['Subject'] = 'Wichteln 🎄' + msg['Message-ID'] = make_msgid(domain=config['sender'] + .split('@')[1] + .strip('>')) + msg['Date'] = formatdate(localtime=True) + + body = 'Lieb'+r['gender']+' '+r['name']+'!\n\n' + body += 'Du bist heuer Wichtel für '+r['partner']+'.\n' + body += 'Das Geschenk sollte nicht mehr als 75€ kosten.\n\n' + body += 'Frohe Weihnachten!\n— Dein Christkind 👼' + + html = f"""
Lieb{r['gender']} {r['name']}!
Du bist heuer Wichtel für {r['partner']}.
- Das Geschenk sollte nicht mehr als 50€ kosten.
+ Das Geschenk sollte nicht mehr als 75€ kosten.
Frohe Weihnachten!
— Dein Christkind 👼