File tree Expand file tree Collapse file tree
python_script_to_check_website_status Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import requests
2+ import bs4
3+ import smtplib
4+ import os
5+
6+ email_add = os .environ .get ('EMAIL_ADD' )
7+ password = os .environ .get ('EMAIL_PASS' )
8+
9+ def send_email ():
10+ s = smtplib .SMTP ('smtp.gmail.com' , 587 )
11+ s .starttls ()
12+ s .login (email_add , password )
13+ subject = "!!!!!! 100 days of devops site is down"
14+ body = "Check the status of 100 days of devops"
15+ message = f'Subject: { subject } \n \n { body } '
16+ s .sendmail (email_add , email_add , message )
17+ s .quit ()
18+
19+
20+ producturl = "http://100daysofdevops.com/contact-us/"
21+
22+ res = requests .get (producturl , timeout = 5 )
23+ if res .status_code != 200 :
24+ send_email ()
25+
26+ soup = bs4 .BeautifulSoup (res .text ,'html.parser' )
27+
28+ elems = soup .select ('#post-67 > div > div > header > h2' )
29+ try :
30+ if elems [0 ].text != "Welcome" :
31+ send_email ()
32+ except Exception as e :
33+ send_email ()
You can’t perform that action at this time.
0 commit comments