Created
March 10, 2019 00:08
-
-
Save JasonMillward/be5b29c1068fcb31796caad6e97c6919 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 json | |
from urllib2 import Request, urlopen | |
import psutil | |
import os | |
def octoprint(path): | |
q = Request("http://10.0.0.60/api/{}".format(path)) | |
q.add_header("X-Api-Key", "[YOUR API KEY GOES HERE]") | |
a = urlopen(q).read() | |
return json.loads(a) | |
def checkWebcamD(): | |
for proc in psutil.process_iter(): | |
if proc.name() == "mjpg_streamer": | |
return True | |
return False | |
if __name__ == "__main__": | |
printer = octoprint("job") | |
if "Offline" in printer['state'] or "Operational" in printer['state']: | |
if checkWebcamD(): | |
os.system("/etc/init.d/webcamd stop") | |
if "Printing" in printer['state']: | |
# If we are printing, check the webcam | |
# if the webcam service is not running, turn it on | |
if not checkWebcamD(): | |
os.system("/etc/init.d/webcamd start") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment