Skip to content

Instantly share code, notes, and snippets.

@cory2067
Created November 26, 2017 07:56
Show Gist options
  • Save cory2067/f17c9378bb2403fbd377d60062f96d40 to your computer and use it in GitHub Desktop.
Save cory2067/f17c9378bb2403fbd377d60062f96d40 to your computer and use it in GitHub Desktop.
Next House printer monitoring
import bs4
import requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
printers = [
('justinbieber', '2e'),
('next2w', '2w'),
('nalgas', '3e'),
('printerbena', '3w'),
('fourest', '4e'),
('derp', '4w'),
('stirfry', '5e'),
('page-fault', '5w'),
]
for p,wing in printers:
name = '{} ({})'.format(p, wing)
try:
page = requests.get("https://"+p+".mit.edu",verify=False, timeout=5).text
except:
print(name + ': Not online.')
continue
soup = bs4.BeautifulSoup(page, 'lxml')
found = soup.find('',{'id':'SupplyGauge0'})
if not found:
print(name + ": Online, unknown ink level.")
else:
level = found.findAll(text=True)[0]
print(name + ': Online, {} ink.'.format(level))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment