Created
July 12, 2015 00:14
-
-
Save fogleman/710eab8dc08e50720ec0 to your computer and use it in GitHub Desktop.
Fabmo API Wrapper
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 json | |
import requests | |
import sys | |
HEADERS = {'content-type': 'application/json'} | |
class Fabmo(object): | |
def __init__(self, host, port=9876): | |
self.url = 'http://%s:%s' % (host, port) | |
def direct_gcode(self, cmd): | |
url = self.url + '/direct/gcode' | |
data = dict(cmd=cmd) | |
r = requests.post(url, data=json.dumps(data), headers=HEADERS) | |
return r.json() | |
def direct_gcode_file(self, path): | |
with open(path) as fp: | |
cmd = fp.read() | |
return self.direct_gcode(cmd) | |
def main(): | |
args = sys.argv[1:] | |
fabmo = Fabmo(args[0]) | |
print fabmo.direct_gcode_file(args[1]) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment