Archive
Posts Tagged ‘up’
Get an email notification when a site is up
May 9, 2014
Leave a comment
Problem
Today I wanted to submit a paper to a conference but the site that manages submissions (EasyChair) is down for maintenance. I got this message:
EasyChair is Being Moved to a New Server Quite unexpectedly, EasyChair had to be moved to a new server. We are moving the system itself and restoring all data. We are sorry for any inconveniences caused. The move is to be completed during Friday, May the 9th. We cannot give precise time at the moment. We are working hard to make it up and running as soon as possible.
I don’t want to check this site manually. How could I get notified when the site is up?
Solution
I wrote a simple script that regularly checks the site. When it’s up, it sends me an email notification and quits.
Here I reused some functions from my jabbapylib library. You can easily include those functions to make it standalone.
#!/usr/bin/env python
# encoding: utf-8
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from time import sleep
import schedule
from jabbapylib.mail.gmail_send import mail_html
from jabbapylib.web.web import get_page, html_to_text
import sys
URL = 'http://www.easychair.org/'
USERNAME = "..."
PASSWORD = "..."
sender = {
'gmail_user': USERNAME,
'gmail_name': "PyChecker",
'gmail_pwd': PASSWORD,
}
STOP = False
def is_down(url):
"""
Check if the site is down.
Return True if it's down. Otherwise, return False.
"""
html = get_page(url)
text = " ".join(html_to_text(html).split())
return "We are sorry for any inconveniences caused." in text
def job():
global STOP
print()
if is_down(URL):
print("The site is still down.")
else:
print("The site is up.")
mail_html(sender, "[email protected]",
"EasyChair is up!",
"Send your paper: <a href='https://www.easychair.org'>EasyChair</a>.")
print("E-mail notification was sent.")
STOP = True
def main():
schedule.every(5).minutes.do(job)
print("Running...")
while not STOP:
schedule.run_pending()
sleep(10)
sys.stdout.write('.'); sys.stdout.flush()
####################
if __name__ == "__main__":
main()
