Skip to content

Instantly share code, notes, and snippets.

@rslprpr
Forked from codingjoe/coding_challenge.md
Created October 6, 2017 11:55
Show Gist options
  • Save rslprpr/430188283240a0248ba7cd9b576c53de to your computer and use it in GitHub Desktop.
Save rslprpr/430188283240a0248ba7cd9b576c53de to your computer and use it in GitHub Desktop.
Homa's coding challenge

Let's assume you have a co-worker explaining a problem to you and you have to come up with a solution.

Here's your co-worker:

I have to commute to work every day for two hours. An hour to the office and an hour home. The worst part, the train to the office only leaves every hour. So if I miss it, I have to wait another hour.

Can you build me a small script for my computer that reminds me that I need to leave the office to catch my train? Thanks!

Feel free to ask questions in the comments to solve the challenge. You can assume that your co-worker has the latest version of Python installed.

If you are not from Berlin, you should know that our transportation system is called VBB. They have an API ;)

The challenge should not take more than two hours, you do not need to complete it.

import smtplib
import time
import schedule
def job():
FROM = "[email protected]"
TO = ["[email protected]", "2ndaddress", "etc"] # must be a list
SUBJECT = "Train Alert!"
TEXT = """It's time to go home Johannes,
You need to leave the office to catch my train."""
# Prepare actual message
message = """From: %srnTo: %srnSubject: %srn
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
# Send the mail
username = str("[email protected]")
password = str("yourpassword")
server = smtplib.SMTP("smtp.gmail.com", 587, timeout=10)
server.set_debuglevel(1)
server.starttls()
# Check whether the your E-mail account allows to log in
server.login(username, password)
server.sendmail(FROM, TO, message)
print ("The reminder e-mail for catching the train was sent!")
server.quit()
input("Press any key to exit..")
schedule.every().hour.do(job)
if __name__ == "__main__":
while True:
schedule.run_pending()
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment