Last active
April 9, 2021 00:37
-
-
Save keyan/b513346233cf37cb8d246717b9ad2144 to your computer and use it in GitHub Desktop.
Template for when you want to do something, then send an email about it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import smtplib, ssl | |
import requests | |
RECEIVER_EMAIL = '[email protected]' | |
def send_email(name: str): | |
port = 465 | |
sender_email = "[email protected]" | |
password = "a_password" | |
context = ssl.create_default_context() | |
with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server: | |
server.login(sender_email, password) | |
message = f"""\ | |
Subject: EmailBot | |
A message {name} | |
""" | |
server.sendmail(sender_email, RECEIVER_EMAIL, message) | |
while True: | |
found = False | |
url = 'http://google.com' | |
resp = requests.get(url) | |
if 'some string' in str(resp.content): | |
continue | |
else: | |
found = True | |
send_email(name) | |
if not found: | |
print('Not found, sleeping...') | |
time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment