<commit_before>from __future__ import absolute_import
from httplib import BadStatusLine
from .locbitNotifications import locbitMsgDict

import octoprint.plugin
import requests
import flask
import json


Layer = 0
uid = "55de667a295efb62093205e4"
# url = "http://192.168.0.34:3000"
url = "http://api.locbit.com:8888/endpoint"

class LocbitPlugin(octoprint.plugin.StartupPlugin,
			octoprint.plugin.TemplatePlugin,
			octoprint.plugin.SettingsPlugin,
			octoprint.plugin.EventHandlerPlugin,
			octoprint.plugin.AssetPlugin,
			octoprint.plugin.SimpleApiPlugin):


	def get_api_commands(self):
		return dict(
			command1=[],
			command2=["some_parameter"]
		)

	def on_api_command(self, command, data):
		import flask
		if command == "command1":
			parameter = "unset"
			if "parameter" in data:
				parameter = "set"
			self._logger.info("command1 called, parameter is {parameter}".format(**locals()))
		elif command == "command2":
			self._logger.info("command2 called, some_parameter is {some_parameter}".format(**data))

	def on_api_get(self, request):
		import subprocess
		output = subprocess.check_output(['/home/pi/oprint/lib/python2.7/site-packages'
										  '/octoprint_Locbit/qr.py'])
                json_output = json.loads(output)
                
                if 'error' in json_output:
                       return "Invalid QR code"
                else:
                       qr_result = json_output.get('result')
                       
                       if qr_result is None:
                               return "Invalid QR code"
                       
                       qr_result = qr_result.split(",")
 
		       if len(qr_result) == 5:
		               return flask.jsonify(material=qr_result[0], diameter=qr_result[1], color=qr_result[2], length=qr_result[3],
								 muid=qr_result[4])
		       else:
		               return "Invalid QR code"

	def on_after_startup(self):
		self._logger.info("Hello world! I am: %s" % self._settings.get(["did"]))

	def get_settings_defaults(self):
		return dict(did="TEST_PRINTER")

	def get_template_configs(self):
		return [
			dict(type="navbar", custom_bindings=False),
			dict(type="settings", custom_bindings=False)<commit_msg>added json error to return qr code message<commit_after>from __future__ import absolute_import
from httplib import BadStatusLine
from .locbitNotifications import locbitMsgDict

import octoprint.plugin
import requests
import flask
import json


Layer = 0
uid = "55de667a295efb62093205e4"
# url = "http://192.168.0.34:3000"
url = "http://api.locbit.com:8888/endpoint"

class LocbitPlugin(octoprint.plugin.StartupPlugin,
			octoprint.plugin.TemplatePlugin,
			octoprint.plugin.SettingsPlugin,
			octoprint.plugin.EventHandlerPlugin,
			octoprint.plugin.AssetPlugin,
			octoprint.plugin.SimpleApiPlugin):


	def get_api_commands(self):
		return dict(
			command1=[],
			command2=["some_parameter"]
		)

	def on_api_command(self, command, data):
		import flask
		if command == "command1":
			parameter = "unset"
			if "parameter" in data:
				parameter = "set"
			self._logger.info("command1 called, parameter is {parameter}".format(**locals()))
		elif command == "command2":
			self._logger.info("command2 called, some_parameter is {some_parameter}".format(**data))

	def on_api_get(self, request):
		import subprocess
		output = subprocess.check_output(['/home/pi/oprint/lib/python2.7/site-packages'
										  '/octoprint_Locbit/qr.py'])
                json_output = json.loads(output)
                
                if 'error' in json_output:
                       return flask.jsonify(error=json_output['error']) 
                else:
                       qr_result = json_output.get('result')
                       
                       if qr_result is None:
                               return flask.jsonify(error="QR code read failure. Uknown error.") 
                       
                       qr_result = qr_result.split(",")
 
		       if len(qr_result) == 5:
		               return flask.jsonify(material=qr_result[0], diameter=qr_result[1], color=qr_result[2], length=qr_result[3],
								 muid=qr_result[4])
		       else:
		               return flask.jsonify(error="Invalid QR code") 

	def on_after_startup(self):
		self._logger.info("Hello world! I am: %s" % self._settings.get(["did"]))

	def get_settings_defaults(self):
		return dict(did="TEST_PRINTER")

	def get_template_configs(self):
		return [
			dict(type="navbar", custom_bindings=False),
			dict(type="settings", custom_bindings=False)
{'fraction_non_alphanumeric': 0.11233480176211454, 'fraction_numerical': 0.02158590308370044, 'mean_word_length': 2.781015820149875, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6317030', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1384, 'n_words': 277}