ReportBot: automated viewing of website reports
Daftar isi
ReportBot: automated website report viewing system
Introduction
iSIKHNAS ReportBot is intended for automated hands-off demonstration and display of the iSIKHNAS web site, initially intended for use in the Director General's Diorama room, but potentially for others that want to demonstrate the system or to have automated display for monitoring the system.
This system provides automated on-screen display of all the available reports on the iSIKHNAS web site. In an existing web browser (such as Chrome), the system shows one of the reports, waits, then automatically displays the next report, moving through all the reports on the system, and then looping through all indefinitely until the system is manually shut down.
It is run by installing some software and scripts on a standalone internet connected computer, which drives the display.
Installation
- Install the appropriate Python 2.7 for your system. Download from https://www.python.org/downloads/ and following the installation instructions.
- Download the Selenium Python bindings (using the green button at the top of the page) at https://pypi.python.org/pypi/selenium
- Decompress the tar.gz file, and save the directory structure (it should be saved as a directory called something like selenium-2.42.1)
- From the saved directory, under the 'py' directory, copy the entire 'selenium' directory and subdirectories into the 'Lib' directory of the python install (normally C:\Python27\Lib)
- Install the web driver software
- Download the right web driver for the web browser that will be used from http://code.google.com/p/selenium/w/list?can=2&q=label=WebDriver&colspec=PageName%20Summary%20Changed%20ChangedBy
- Save it into the Python install directory (normally C:\Python27)
- Install the python script
- Copy and save the script below into a file called ReportBot.py. Be careful to make sure that there are no extra leading spaces, and that all the indentations are preserved correctly.
Python code
import time import re from selenium import webdriver import sys class ReportBot: def __init__(self, arg): self.username, self.password, d = arg self.delay = float(d) self.pages = [] # get the driver self.options = webdriver.ChromeOptions() # get rid of the startup message self.options.add_argument('--test-type') self.browser = webdriver.Chrome() self.winheight = self.browser.get_window_size()['height'] # open the site self.browser.get('http://www.isikhnas.com') # log in self.browser.find_element_by_id('LoginForm_username').send_keys(self.username) self.browser.find_element_by_id('LoginForm_password').send_keys(self.password) self.browser.find_element_by_name('yt0').click() time.sleep(5) def shutdown(self): # logout and close the browswer window self.browser.get("https://www.isikhnas.com/en/logout") time.sleep(10) self.browser.close() def getReports(self): #get a list of all the links to reports print "making pages" p = re.compile('(rout\?id=|reports/|reportInterface/table/)(\d+)') print "finding links" links = self.browser.find_elements_by_xpath("//a") for l in links: try: href = l.get_attribute("href") m = p.search(href) if m: self.pages.append("https://www.isikhnas.com/id/reports/{0}".format(m.group(2))) print "+ {0}".format(href) else: print "- {0}".format(href) except: pass def showreports(self): self.getReports() # loop through the list try: while True: # loop through the list for p in self.pages: self.browser.get(p) body = self.browser.find_elements_by_id("container") height = body[0].size['height'] time.sleep(self.delay) scheight = 0 while scheight < height-self.winheight: self.browser.execute_script("window.scrollBy(0, 1);") scheight += 1 except KeyboardInterrupt: self.shutdown(); if __name__ == "__main__": # get the parameters arg = sys.argv[1:] if len(arg) != 3: print "iSIKHNAS ReportBot\nUsage: ReportBot.py username password delay" else: reporter = ReportBot(sys.argv[1:]) reporter.showreports();