Last active
February 13, 2020 19:52
-
-
Save mightywombat/5cd816a640ff89c487058328d717f7e3 to your computer and use it in GitHub Desktop.
Wakefulness script for work printer
This file contains 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 mechanize | |
# DEFINE PRINTER NAMES, IPs, AND DEFAULT STATUS (FALSE) | |
# FUTURE VERSION WILL REFERENCE EXCEL SHEET FOR PRINTER IPS FOR SCALABILITY | |
printers = [ | |
{'name': 'N1', 'ip': '10.3.16.32', 'status': 0}, | |
{'name': 'N2', 'ip': '10.3.8.30', 'status': 0}, | |
{'name': 'P1', 'ip': '10.3.16.31', 'status': 0}, | |
{'name': 'P3', 'ip': '10.3.16.30', 'status': 0} | |
] | |
# HANDLE ROBOT EXCEPTIONS | |
user_agent = [('User-agent', | |
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36' | |
)] | |
# LOAD METER READ PAGE FROM PRINTER, IF SUCCESSFUL SET PRINTER IS UP TO TRUE, ELSE FALSE | |
br = mechanize.Browser() | |
for device in printers: | |
device["status"] = 0 | |
try: | |
if br.open('http://' + device["ip"] + '/wcd/system_counter.xml', timeout=10.0): | |
device["status"] = 1 | |
print(device["name"] + ' is up.\n') | |
else: | |
device["status"] = 0 | |
print(device["name"] + ' is DOWN!\n') | |
except: | |
print(device["name"] + ' is *probably* down.\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment