Skip to content

Commit

Permalink
Fixed excel table not updating
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitor Seger Zeni committed Nov 20, 2017
1 parent bb940c3 commit c2b2b93
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
from openpyxl import load_workbook


def sendEmailToRecipient(server,user,recipient,html) :
mail = createEmailMessageFromHTML(user,recipient.strip(),html)
def sendEmailToRecipient(server,user,recipient,html) :
r = recipient.strip()
mail = createEmailMessageFromHTML(user,r,html)
try:
server.sendmail(user, recipient.strip(), mail.as_string())
server.sendmail(user,r, mail.as_string())
return True
except smtplib.SMTPException:
return False
Expand Down Expand Up @@ -62,7 +63,7 @@ def getAvailableRecipients(ws) :

for row in ws.iter_rows(min_row=2, min_col=1, max_row=ws.max_row, max_col=3) :
if row[2].value == 0 :
available_recipients[row[0].value.lower().title().strip()] = row[1].value.lower().strip()
available_recipients[row[0].value] = row[1].value

return available_recipients

Expand Down Expand Up @@ -164,13 +165,13 @@ def main(args):

print("Homens selecionados:")
for r in selected_male_recipients :
print("{0:50} {1:40}".format(r,selected_male_recipients[r]))
print("{0:50} {1:40}".format(r.lower().title().strip(),selected_male_recipients[r].lower().strip()))

print("")

print("Selected female recipients")
for r in selected_female_recipients :
print("{0:50} {1:40}".format(r,selected_female_recipients[r]))
print("{0:50} {1:40}".format(r.lower().title().strip(),selected_female_recipients[r].lower().strip()))

accepted = query_yes_no("Você aceita a seleção?")

Expand All @@ -182,11 +183,11 @@ def main(args):
# Send to female recipients
print("Enviando para as mulheres...")
for r in selected_female_recipients :
name = "Professora " + r.split()[0] + "!"
name = "Professora " + r.lower().title().split()[0] + "!"
m = replaceNameInHTMLMessage(htmlmsg,name)
if sendEmailToRecipient(server,user,selected_female_recipients[r],m) :
updateRecipientTable(filename,wb,female_recipients_sheet,r)
print("E-mail enviado para {}. Tabela atualizada!".format(r))
print("E-mail enviado para {}. Tabela atualizada!".format(r.lower().title().strip()))
time.sleep(5)
else :
print("Falha no envio. Você pode estar spammando. Tente de novo mais tarde.")
Expand All @@ -196,11 +197,11 @@ def main(args):
# Send to male recipients
print("Enviando para os homens...")
for r in selected_male_recipients :
name = "Professor " + r.split()[0] + "!"
name = "Professor " + r.lower().title().split()[0] + "!"
m = replaceNameInHTMLMessage(htmlmsg,name)
if sendEmailToRecipient(server,user,selected_male_recipients[r],m) :
updateRecipientTable(filename,wb,female_recipients_sheet,r)
print("E-mail enviado para {}. Tabela atualizada!".format(r))
updateRecipientTable(filename,wb,male_recipients_sheet,r)
print("E-mail enviado para {}. Tabela atualizada!".format(r.lower().title().strip()))
time.sleep(5)
else :
print("Falha no envio. Você pode estar spammando. Tente de novo mais tarde.")
Expand Down

0 comments on commit c2b2b93

Please sign in to comment.