Skip to content

Commit

Permalink
added finished indicator and migrated to f-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
alandgton committed Jun 6, 2020
1 parent da4f366 commit d872228
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions send.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def prompt_recipients():
while True:
print_barrier()
print("Which state officials do you want to send emails to?")
if cart: print("Cities chosen: ", cart, "\n")
if cart: print(f'Cities chosen: {cart}\n')
state_options = { v:k for v,k in enumerate(recipients.get_states()) }
for idx, opt in state_options.items():
print(idx, "->", opt)
Expand All @@ -82,7 +82,7 @@ def prompt_recipients():
city_options = { v:k for v,k in enumerate(recipients.get_cities(state)) }
print_barrier()
print("Which city officials do you want to send emails to?")
if subcart: print("Cities chosen: ", subcart, "\n")
if subcart: print(f'Cities chosen: {subcart}\n')
for idx, opt in city_options.items():
print(idx, "->", opt)
print("Enter blank (nothing) when done.")
Expand Down Expand Up @@ -112,14 +112,15 @@ def prompt_recipients():
if not recv:
sys.exit("ABORT: no recipients selected.")

print("\nSending emails to %d state/local officials...\n" % (len(recv)))
print(f'\n{len(recv)} recipients selected.\n')

return recv


port = 465 # standard port for SMTP over SSL
smtp_server = "smtp.gmail.com"

send = 0
recv = prompt_recipients()
subject, message = prompt_email()
src_name, src_email, password = prompt_login()
Expand Down Expand Up @@ -148,7 +149,10 @@ def prompt_recipients():
print(msg.as_string())

server.send_message(msg)
send += 1
break
except smtplib.SMTPException:
print("Unexpected error... trying again in 10 seconds.")
time.sleep(10)

print(f'\nSuccessfully sent {send} emails!\n')

0 comments on commit d872228

Please sign in to comment.