Created
          March 13, 2022 16:33 
        
      - 
      
 - 
        
Save NWMichl/3114f785a3101fa824ec38ab83bca0bf to your computer and use it in GitHub Desktop.  
    Simple Website Checker: Compares the number of <keyword> mentions to a static value and notifies of changes by email
  
        
  
    
      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 requests | |
| import smtplib | |
| from email.mime.text import MIMEText | |
| # Website Checker: Compares the number of <keyword> mentions to a static value and notifies of changes by email | |
| url = 'www.example.com' | |
| header = {'User-Agent': 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0'} | |
| keyword = 'example' | |
| current_number = 5 | |
| smtp_server = 'snmp.example.com' | |
| smtp_port = 587 | |
| smtp_username = '[email protected]' | |
| smtp_password = '*******************' | |
| mail_from = '[email protected]' | |
| mail_to = '[email protected]' | |
| def mail_out(msg_body): | |
| server = smtplib.SMTP(host=smtp_server, port=smtp_port) | |
| server.ehlo() | |
| server.starttls() | |
| server.login(smtp_username, smtp_password) | |
| msg = MIMEText(msg_body) | |
| msg['From'] = mail_from | |
| msg['To'] = mail_to | |
| msg['Subject'] = 'Website Checker' | |
| server.send_message(msg) | |
| server.quit() | |
| try: | |
| response = requests.get(url, headers=header) | |
| except requests.exceptions.RequestException as e: | |
| mail_out('ERROR: ' + str(e)) | |
| else: | |
| word_count = response.text.split().count(keyword) | |
| if word_count != current_number: | |
| mail_out('Websites changed to ' + str(word_count) + ' x ' + keyword + ' : '+ url) | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment