Skip to content

Instantly share code, notes, and snippets.

@zarya

zarya/epc.py

Created Mar 4, 2019
Embed
What would you like to do?
#!/usr/local/bin/python
import requests
import sys
from html.parser import HTMLParser
class MyHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
if tag == "meta":
if attrs[0][1] == "powerstate":
port = attrs[1][1].split(",")
if self.port == int(port[0]):
if port[1] == "1":
print("ON")
else:
print("OFF")
parser = MyHTMLParser()
if len(sys.argv) < 3:
raise Exception('your missing something')
parser.port = int(sys.argv[2])
if len(sys.argv) > 3:
url = "http://%s/SWOV.CGI?s%i=%i" % (sys.argv[1],int(sys.argv[2]),int(sys.argv[3]))
r = requests.get(url)
else:
url = "http://%s" % sys.argv[1]
r = requests.get(url)
parser.feed(r.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.