Skip to content

Commit 79c9db4

Browse files
committed
Bug Fixes
1 parent 78e640c commit 79c9db4

File tree

7 files changed

+23
-46
lines changed

7 files changed

+23
-46
lines changed

Diff for: .vscode/settings.json

-3
This file was deleted.

Diff for: automate.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@
2020
for participant in participants:
2121
# Checking if the participant was sent a mail previously
2222
if participant['email'] not in sent_mails:
23+
name = participant['name']
24+
email = participant['email']
25+
phone = participant['phone']
26+
payment_status = participant['payment']
27+
2328
# Generating a message from the template
24-
msg = _render_template(participant['name'], participant['payment'])
29+
message = _render_template(name, payment_status)
30+
2531
# Generating a custom image
26-
image_path = pass_gen(participant['name'], participant['email'], participant['phone'])
32+
image_path = pass_gen(name, email, phone)
33+
2734
# Sending the message to the participant via mail
28-
response = sendmail(to_email=participant['email'], message=msg, image_path=image_path)
35+
response = sendmail(email, message, image_path, payment_status)
2936
print(response)
30-
if response['email_status'] == "Success" and participant['payment'] == "paid":
37+
38+
if response['email_status'] == "Success" and payment_status == "paid":
3139
# if mail was sent successfully append the email to sentmails.txt
3240
write_file(participant['email'])

Diff for: file_utils.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ def write_csv(data):
2424
def read_file():
2525
# opening the file in read mode and reading lines
2626
with open("sentmails.txt", 'r') as f:
27-
sent_mails = f.readlines()
27+
sent_mails = f.read().split('\n')[:-1]
28+
# Another way
29+
# sent_mails = [mail.strip() for mail in f.readlines()]
2830
return sent_mails
2931

3032

3133
def write_file(mail):
3234
# opening the file in append mode and appending the mail at the end
3335
with open("sentmails.txt", 'a') as f:
34-
f.write(mail + "\n")
36+
f.write(mail + '\n')

Diff for: mail.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import smtplib
55

66

7-
def sendmail(to_email, message, image_path):
7+
def sendmail(to_email, message, image_path, payment_status):
88

99
from_email = ""
1010
msg = MIMEMultipart('alternative')
@@ -16,10 +16,11 @@ def sendmail(to_email, message, image_path):
1616
msg.attach(content)
1717

1818
# This example assumes the image is in the given directory
19-
fp = open(image_path, 'rb')
20-
msgImage = MIMEImage(fp.read())
21-
fp.close()
22-
msg.attach(msgImage)
19+
if payment_status == 'paid':
20+
fp = open(image_path, 'rb')
21+
msgImage = MIMEImage(fp.read())
22+
fp.close()
23+
msg.attach(msgImage)
2324

2425
response = {}
2526
try:

Diff for: sentmails.txt

-9
This file was deleted.

Diff for: studentdetails.csv

-22
This file was deleted.

Diff for: templates/message.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Hi {{name}},
2-
{% if payment == 'paid' %}
2+
{% if payment_status == 'paid' %}
33
This mail is to confirm your payment for the event. Attached with this mail is the pass which will be needed as proof for confirmation.
44
{% else %}
55
We noticed you have registered for our event. But, we haven't recieved any payments. Please make sure to confirm your presence by paying a refundable deposit.

0 commit comments

Comments
 (0)