#!/usr/bin/python # Requireed python modules: # * Mechanize # * BeatifulSoup # apt-get install python-mechanize python-beautifulsoup beep from mechanize import Browser from mechanize import _response from BeautifulSoup import BeautifulSoup import time import sys import os savedVal1 = 0 class CheckDevice: def __init__(self): #constructor self.savedVal1 = 0 def beep(self): os.system("beep -l 200 -r 2") def printTime(self): os.system("date"); def checkVars(self): br = Browser() try: br.open("http://t-hoerup.dk/test.html") soup = BeautifulSoup( br.response().read() ) rows = soup.findAll('tr') for row in rows: key = row.contents[1].string val = row.contents[3].string # print "key ", key # print "val ", val if (key == "Key1"): if (val != self.savedVal1): self.beep() self.printTime() print "Val1 has changed %s -> %s\n" % ( str(self.savedVal1), str(val) ) self.savedVal1 = val except: print "Error, probably a 404 : ", sys.exc_info() # print "----------------------------- done-------------------------" def main(): cd = CheckDevice() #dumb continous main-loop abort with ctrl+c and ignore the error output while (1): cd.checkVars() time.sleep(1) #seconds #Finally, launch main function main()