def run(email_list, url, source_email, sleeptime_set=None): current_hash, current_file = get_hash(url) # Get the current hash, which is what the website is now if sleeptime_set is not None: sleeptime = sleeptime_set while 1: # Run forever added_name_list = [] removed_name_list = [] new_hash, new_file = get_hash(url) if new_hash == current_hash: # If nothing has changed print("nothing changed") else: # If something has changed current_hash = new_hash added_pup_text = "" removed_pup_text = "" for line in difflib.unified_diff(str(current_file), str(new_file)): if not re.match(r'-', line): added_pup_text += str(line.strip('+-!')) else: removed_pup_text += str(line.strip('+-!')) added_name_list = HTMLParser.parse_html(added_pup_text) removed_name_list = HTMLParser.parse_html(removed_pup_text) if len(added_name_list) > 0: for email in email_list: SendEmail.authorize_and_send_message(str(added_name_list), email, source_email) print("Changed with added pups, email sent.") if len(removed_name_list) > 0: print("--Pups removed: " + str(removed_name_list)) if len(removed_name_list) <= 0 and len(added_name_list) <= 0: print("Changed but no pups added or removed.") time.sleep(sleeptime)
import difflib import SendEmail import re import HTMLParser current_file = open("Adoptable Animals.html", "r") new_file = open("Adoptable Animals Mod.html", "r") email = "" for line in difflib.unified_diff(str(current_file.readlines()), str(new_file.readlines())): if not re.match(r'-', line): email += str(line.strip('+-!')) name_list = HTMLParser.parse_html(email) SendEmail.authorize_and_send_message(str(name_list)) print(name_list)