def trgr(songFileName= None, wallpaperFileName = None): # TODO move selected song and wallpaper to /AfterEffects/SourceFiles/ # Write Track info for AscentTemplate musicFileList = glob(AESourcePath + '*.mp3') if musicFileList.__len__() != 1: error("Erroneous number of mp3s in /AfterEffects/SourceFiles/") else: track = str(musicFileList[0])[str(AESourcePath).__len__():] track = track.split('-')[:-1] artist = track[0] song = track[1] entry = str(str(artist.title() + '-' + song.title())) setTrack(entry) muterun_js(AE_Script) # run ae script
def behavior_alert(): """ Alert user when reach the time in user_behavior It will ask user for permission before execute """ time = datetime.datetime.now() h = time.hour m = time.minute conn = sqlite3.connect('modules/data/user_behavior.db') cur = conn.cursor() cur.execute('select * from behavior') rows = cur.fetchall() for row in rows: final = [] print("Current time || hour:", h, " minute: ", int(m), " time to open or close:", row[2]) if (int(row[2]) == int(h) and int(m) == 0): print(row[2], row[3]) if row[3] == 1: final.append("open") event = 0 command = "เปิด" elif row[4] == 1: final.append("close") event = 1 command = "ปิด" final.append(row[1]) tts("ต้องการที่จะ" + command + "ไฟ" + row[1] + "หรือไม่คะ") text = stt() print(event) if any(["ปิด" in text, "ใช่" in text]) & event == 1: run = ",".join(final) success = muterun_js('plug/plugForBot.js', run) if success.exitcode == 0: print(success.stdout.decode("utf-8")) elif any(["เปิด" in text, "ใช่" in text]) & event == 0: run = ",".join(final) success = muterun_js('plug/plugForBot.js', run) if success.exitcode == 0: print(success.stdout.decode("utf-8")) else: tts("ไม่เข้าใจคำสั่งค่ะ") print(run) print(success.exitcode) return 0
def __init__(self, patch_size, batch_size, identity): self.files = muterun_js( "./application/dataQuery.js", identity).stdout.decode('utf-8').split("\n")[7:-2] self.whole_size = int( muterun_js("./application/getTotalEnrollCount.js", identity).stdout.decode('utf-8').split("\n")[-2]) self.train_img = [] self.train_mask = [] self.preprocess() self.length = len(self.train_img) self.train = cycle(zip(self.train_img, self.train_mask)) self.patch_size = patch_size self.batch_size = batch_size self.patch_length = self.length
def get_DOI_JSTOR(JSTOR_link, attempt=1): response = muterun_js("puppet-jstor.js", JSTOR_link) if response.exitcode == 0: soup = BeautifulSoup(response.stdout, "html.parser") captcha = soup.find(id="g-recaptcha-response") if not captcha: doi_div = soup.find("div", class_="doi") if doi_div: possible = re.search(r"DOI: (.*)", doi_div.text) if possible: print("JSTOR DOI Found: " + possible.group(1)) return possible.group(1) else: return None else: return None elif attempt < 5: print("JSTOR captcha, retrying...") return get_DOI_JSTOR(JSTOR_link, attempt + 1) else: return None elif attempt < 5: print("No JSTOR response, retrying...") return get_DOI_JSTOR(JSTOR_link, attempt + 1) else: return None
def run_cyberchef_function(self, input, action, args): #Javascript that ties together the execution with self.setupOpTemporaryCopy(input, action, args) as tf: response = muterun_js(tf.name) return self.handleOutput(response)
def generate_key_pair(cls): response = muterun_js(cls.current_dir + '/js/GenerateKeys.js') if response.exitcode == 0: data = load_data(response.stdout) return data else: raise GenerateKeysException(response.stderr)
def newaccount(self, config): """ node CreateAccount.js 'http://172.18.0.1:8888' 'eosio' 'mytest12' '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3' '5JuaVWh3LDh1VH69urCdCa3A2YiQydbsLM1ZtGgsTXLYouxaTfc' 'EOS7vTHtMbZ1g9P8BiyAGD7Ni7H6UALVLVCW13xZrXT4heCBke3it' 'EOS8KKKYBBdwrmXRRynDXSxTX2qoT9TA4agahXXF4ccUgRCy81RNc' 8192 '100.0000 SYS' '100.0000 SYS' 0 """ arguments = '"%s" "%s" "%s" "%s" "%s" "%s" %s "%s" "%s" %s' % ( self.http_address, config["creator"] if "creator" in config else "eosio", config["name"], self.key_provider, config["owner_public_key"], config["active_public_key"], config["buyrambytes_bytes"] if "buyrambytes_bytes" in config else 8192, config["delegatebw_stake_net_quantity"] if "delegatebw_stake_net_quantity" in config else "100.0000 SYS", config["delegatebw_stake_cpu_quantity"] if "delegatebw_stake_cpu_quantity" in config else "100.0000 SYS", config["delegatebw_transfer"] if "delegatebw_transfer" in config else 0, ) response = muterun_js( self.current_dir + "/js/CreateAccount.js", arguments=arguments ) if response.exitcode == 0: print(response.stdout.decode("utf8")) else: raise CreateAccountException(response.stderr)
def insertthroughnodejs(a): print("Going through the insertion function") response=muterun_js("transaction.js",a) test1=re.match("AssetID(.*)AssetEND",response.stdout) print (response.stdout) Obtained_Asset_ID=test1.group(1) print Obtained_Asset_ID
def load_to_gdo(label, layer): print("Posting to GDO...") response = muterun_js("./load_to_gdo.js", arguments=label + " " + layer) if response.exitcode == 0: print(response.stdout) else: print(response.stderr)
def execute(self, results): """ Executes the action_block in the PinFile """ for action in self.action_data["actions"]: result = {} context = self.action_data.get("context", True) path = self.action_data["path"] file_path = "{0}/{1}".format(path, action) res_str = json.dumps(results, separators=(',', ':')) command = self.add_ctx_params(file_path, context) run_data = muterun_js(command, arguments=res_str) print(run_data.stdout) data = run_data.stderr try: if data: result['data'] = json.loads(data) except ValueError: print("Warning: '{0}' is not a valid JSON object. " "Data from this hook will be discarded".format(data)) result['return_code'] = run_data.exitcode result['state'] = str(self.state) results.append(result) return results
def request_to_ledger(iot_record): rec_id = int(iot_record[0]) # print timestamps.keys() # print rec_id # print rec_id in timestamps.keys() # if rec_id in timestamps.keys(): # delay1 = time.time() - timestamps[rec_id] # print "timestamp " # print timestamps[rec_id] # print "delay 1 : " # print delay1 response = muterun_js('invoke.js', "{} {} {} {} {} {} {} {}".format(*iot_record)) if response.exitcode == 0: # print "blockchain not connected" print(response.stdout) if rec_id in timestamps.keys(): update_avg.acquire() delay2 = time.time() - timestamps[rec_id] print("new delay : ", delay2) avag_time.append(delay2) new_avg_mean = np.mean(avag_time) new_avg_std = np.std(avag_time) print("avg delay time : ", np.mean(avag_time)) print("std on delay time : ", np.std(avag_time)) f = open(log_name, "a+") f.write("DELAY mean:%f std:%f \n" % (new_avg_mean, new_avg_std)) f.close() update_avg.release() else: sys.stderr.write(response.stderr)
def get_user(self, url): print("Fetching data. Please wait...") raw_data = muterun_js('/users/ariel/programming/LinkedInRefactored/parser/scraper.js', url) print("Done fetching data.") # Handle error executing script if raw_data.exitcode != 0: print(raw_data.exitcode) print(raw_data.stderr) raise RuntimeError("Error executing node script: ", raw_data.exitcode) return raw_data = raw_data.stdout data = self._clean_data(raw_data) self._find_useful_fields(data) return User(name=self._name, title=self._title, position=self._current_position, summary=self._summary, skills=self._skills, experience=self._experience, education=self._education)
def node_script(): response = muterun_js( 'sdcd/Frontend/socket_udp.js') #PATH TO NODE JS SCRIPT if response.exitcode == 0: print(response.stdout) else: sys.stderr.write(response.stderr)
def insertblock(self,item,bbox): dim=str(bbox).strip("()") dim= dim.replace(',', '') dim=str(dim) result=self.intersect(bbox) if not self.hash: self.hash='0' if not result: a=[str(self.hash),str(dim),str(item)] b=":".join(a) b=str(b) print(type(b)) print b b=b.replace(' ','-') response=muterun_js("transaction.js",b) print response.stdout test1=re.match("AssetID(.*)AssetEND",response.stdout) Obtained_Asset_ID=test1.group(1) self.insert(Obtained_Asset_ID,bbox) print ("Property Sucessfully inserted"+str(dim)) self.hashcal() else: print ("There is an intersection with") print ([i for i in result])
def build(self, script, data): network = { '6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988' : "0x17", '578e820911f24e039733b45e4882b73e301f813a0d2c31330dafda84534ffa23' : "0x1E", '313ea34c8eb705f79e7bc298b788417ff3f7116c9596f5c9875e769ee2f4ede1' : '0x2D' }[self.client.nethash] template = self.env.get_template(script + ".py").render({ **{ "network" : network }, **data }) transactionScript=script + ".js" with open(transactionScript, "wt") as fh: fh.write(template) response = muterun_js(transactionScript) if response.exitcode == 0: os.remove(transactionScript) return json.loads(response.stdout.decode('utf-8')) else: sys.stderr.write(response.stderr.decode('utf-8'))
def scraper(): response = req(lookup_url) html_page = response.read() response.close() #website soup'ed soupypage = soup(html_page, "html.parser") #making sure the UPC is valid and also exists in the database check = soupypage.h2.text if (check == "Item Not Found") or (check == "UPC Error"): return #scrape based on tags itemdescription3 = str( soupypage.find("table", { "class": "data" }).findAll("tr")[3].findAll("td")) itemdescription2 = str( soupypage.find("table", { "class": "data" }).findAll("tr")[2].findAll("td")) if (itemdescription3.find("Description", 0, len(itemdescription3))) != -1: itemdescription = soupypage.find("table", { "class": "data" }).findAll("tr")[3].findAll("td")[2].text print("hi") elif (itemdescription2.find("Description", 0, len(itemdescription2))) != -1: itemdescription = soupypage.find("table", { "class": "data" }).findAll("tr")[2].findAll("td")[2].text print("he") else: itemdescription = soupypage.find("table", { "class": "data" }).findAll("tr")[1].findAll("td")[2].text print("ho") print("UPC:" + upc) print("The item is: " + itemdescription) muterun_js('node/index.js', "'" + itemdescription.lower() + "'") #if success: # print("success") #else: # print("fail") now = datetime.datetime.now() print("Current date and time : " + now.strftime("%Y-%m-%d %H:%M:%S"))
def deployContractForPost(): response = muterun_js('/root/scriptTest/EtherUtils.js') if response.exitcode == 0: addr = response.stdout[:-1] return addr else: print('Deploy contract error') return ''
def generate_key_pair(cls): response = muterun_js(cls.current_dir + '/js/GenerateKeys.js') if response.exitcode == 0: true_string = response.stdout.decode('utf8') data = json.loads(true_string) return data else: raise GenerateKeysException(response.stderr)
def query_chaincode(user, channel, chaincode, function, parameters): parameters = list2str(parameters) args = user + ' ' + channel + ' ' + chaincode + ' ' + function + ' ' + parameters response = muterun_js('node-connectors/query.js', arguments=args) if response.exitcode == 0: return response.stdout.split('Response is ', 1)[1] else: sys.stderr.write(response.stderr) return None
def fg_make_prob(situation): if sys.version_info[0] >= 3: args = ' '.join("--%s=%r" % (key,val) for (key,val) in situation.items()) else: args = ' '.join("--%s=%r" % (key,val) for (key,val) in situation.iteritems()) model_fg = muterun_js('model-fg/model-fg.js', args) stdoutResults = model_fg.stdout stdoutSplit = stdoutResults.split() return stdoutSplit[-1]
def generateExcelFile(): eventCode = tkSimpleDialog.askstring(title = "Event Code Entry", prompt = "Enter event code:") response = muterun_js('../jsAssets/writeExcel.js', eventCode) if(response.exitcode == 0): print 'worked' print response.stdout else: print 'didnt work'
def get_contract_gas(path): script_path = os.path.join(os.getcwd(), 'smartpollution', 'static', 'smartcontracts', 'estimateCosts.js') response = muterun_js(script_path + ' "' + path + '"') print("REsponse:" + str(response._getAttributeDict().get('stderr'))) print("stdout:" + str(response._getAttributeDict().get('stdout'))) contr_info = response._getAttributeDict().get('stdout') print('CONTR_info:' + str(contr_info)) return contr_info
def createEtherAddr(): response = muterun_js('/root/scriptTest/createAccount.js') if response.exitcode == 0: addr = response.stdout[:-1] print(addr) with open("ethaddr.txt", "w") as f: f.write(addr) else: print('create Ethereum address error')
def usrweb_view(request): print("in usrweb_view") # HttpResponseRedirect("bokeh_app/plot.html") params = {} # taking the last website from the databased and calling the parameters usrWebSite = WebInfo.objects.values('website').order_by('-created_date')[0]['website'] response = muterun_js('webtest_analysis.js', usrWebSite) # data = serializers.serialize("json", response) params['web_address'] = usrWebSite def prepare(data_in): content= data_in line = content.split('\n') for each in line: values=each.split(':') # lenght should be two if len(values) == 2: key, value = values params[key] = value elif len(values) == 1: print("value is 1: ", values) else: print("in the else ",len(values), " ", values) return params def renameParms(data): mod_dic = {} key = {'web_address':'', "load_time":'', "first_byte":'', "start_render":'', "speed_Index":'', "dom_elements":'', "doc_complete_Requests":'', "doc_complete_Byets":'',"fully_time":'', "fully_requests":'', "fully_bytes":''} for parm, val in zip(key.keys(),data.values()): # print(parm," ", val) mod_dic[parm] = val return mod_dic if response.exitcode == 0: print("SUCCEED") # print(response.stdout) data = str((response.stdout).decode('utf8').replace("'",'"')) start = data.find('Load time') end = data.find('Waterfall view') #passing the SELECTED (SLISED) result to a dictionary print(prepare(data[start:end])) data_dic = renameParms(prepare(data[start:end])) # passing the dictionary to the model ParaInfo.objects.create(**data_dic) # dic_para = ParaInfo.objects.values().filter(web_address= WebInfo.objects.values('website').order_by('-created_date')[0]['website'])[0] helper(2).write_model_toCSV(data_dic) # write_model_toCSV(data_dic) else: print("FAILED") sys.stderr.write(str(response.stderr)) # print(msg) return render(request, "bokeh_app/process.html")
def react(): observation = str(request.get_json()) response = muterun_js('./logic.js', observation) if response.exitcode == 0: print(response.stdout.decode("utf-8").rstrip()) else: print(response.stderr.decode("utf-8").rstrip()) return jsonify(response.stdout.decode("utf-8").rstrip())
def get(self, request, *args, **kwargs): renderer = os.path.join(BASE_DIR, 'static/server/main.js') context = self.get_context_data(**kwargs) response = muterun_js(renderer, request.build_absolute_uri(request.path)) if DEBUG: return HttpResponse(response.stdout) return HttpResponse( response.stdout) if '</html>' in response.stdout.decode( "utf-8") else self.render_to_response(context)
def hex2tronwif(hexstr): spath = os.path.dirname(os.path.abspath(__file__)) sname = 'hextob58.js' js_path = os.path.join(spath, sname) response = muterun_js(js_path, hexstr) if response.exitcode == 0: return response.stdout.decode().strip() else: sys.stderr.write(response.stderr.decode().strip())
def run(self, queue): #print(self.generate_code(self.params)) js = shell.muterun_js("javascript/train_webworker.js", arguments=self.generate_arguments()) #print(js.stdout) try: result = float(js.stdout[-6:]) except ValueError: print("Could not extract result from javascript output. Received: " + js.stdout) #print(result) queue.put(result)
def get_variables(latex): """ Parse latex code into a list of strings where each string represents one variable :param latex: Latex code :return: List of strings if successful; ['-1'] if parse error """ processed = latex.replace(' ', '[space]') processed = processed.replace('\\', '[backslash]') processed = processed.replace('(', '{') processed = processed.replace(')', '}') response = muterun_js(os.path.join(CURRENT_DIR, 'katex/parse.js'), processed) if response.stdout == b'-1\n' or not response.stdout: yield -1 return tree = etree.fromstring(response.stdout) ast = tree.xpath('.//semantics')[0] count = 0 for c in ast.xpath('.//*'): c.attrib['id'] = str(count) count += 1 ngram_kv = {} ngram = [] for row in ast.xpath('.//mrow'): ngram.append([]) for mi in row: if mi.text and mi.tag == 'mi' and mi.text: ngram_kv[mi.attrib['id']] = row.attrib['id'] if mi.text in ['=', '+', '-', '*', '/']: ngram.append([]) continue ngram[-1].append(mi.text) else: ngram.append([]) for sup in tree.xpath('.//msup'): if 'None' not in unparse(sup): yield unparse(sup) for sub in tree.xpath('.//msub'): if 'None' not in unparse(sub): yield unparse(sub) for id in tree.xpath('.//mi'): if id.attrib['id'] not in ngram_kv: if 'None' not in unparse(id): yield unparse(id.text) for _x in ngram: if len(_x) > 0: yield unparse(''.join(_x))
def get_dominant_colors_by_colordiff(db, fs, l_post_id): img_barcode = fs.get(l_post_id).read() my_img = open("myMovieBarcode.png", "wb") my_img.write(img_barcode) my_img.close() # if image is GIF -> convert to JPEG im = Image.open('myMovieBarcode.png') #if im.format =='GIF': im.convert('RGB').save('myMovieBarcode.png') ''' image = cv2.imread("myMovieBarcode.jpg") image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) image = image.reshape((image.shape[0] * image.shape[1], 3)) clt = KMeans(n_clusters=3) clt.fit(image) hist = centroid_histogram(clt) count = 1 dominant_colors = {} for (percent, color) in zip(hist, clt.cluster_centers_): print(percent) color_R = int(color[0]) color_G = int(color[1]) color_B = int(color[2]) real_color = "rgb(" + str(color_R) + ", " + str(color_G) + ", " + str(color_B) + ")" print(real_color) real_color_hex = rgb2hex(color_R, color_G, color_B) print(real_color_hex) # response = muterun_js('colorDiffTest.js ' + str(color_R) + ' ' + str(color_G) + ' ' + str(color_B)) response = muterun_js('color-diff.js ' + str(color_R) + ' ' + str(color_G) + ' ' + str(color_B)) clustered_color = response.stdout.rstrip().decode('ascii') print(clustered_color) dominant_colors[str(count)] = { "realcolor": real_color_hex, "percent": float("{0:.2f}".format(percent*100)), #int(percent * 100), "clusteredcolor": clustered_color } count += 1 ''' response = muterun_js('color-diff.js') colorString = response.stdout.rstrip().decode('ascii') print(colorString) dominant_colors = {} colorPairs = colorString.split(', ') for pair in colorPairs: pairSplit = pair.split(': ') color = pairSplit[0] percentage = pairSplit[1] dominant_colors[color] = float(percentage) print(dominant_colors) # return dominant_colors update_value_in_db(db, l_post_id, "dominantColors", dominant_colors)
def sign_data(cls, raw_data, wif): arguments = "'%s' '%s'" % ( raw_data, wif ) response = muterun_js(cls.current_dir + '/js/SignData.js', arguments=arguments) if response.exitcode == 0: signature = response.stdout.decode('utf8') return signature.replace("\n", "") else: return None
def encrypt_chain_message(cls, privKeySender, pubKeyRecipient, message): arguments = "'%s' '%s' '%s'" % (privKeySender, pubKeyRecipient, message) response = muterun_js(cls.current_dir + '/js/Encrypt.js', arguments=arguments) if response.exitcode == 0: encrypted_msg = response.stdout.decode('utf8') return encrypted_msg.replace("\n", "") else: raise EncryptSecretException(response.stderr)
def convertLtxToMathml(ltx): ltx = "'" + ltx + "'" proc = muterun_js("./nodelib/converter.js", ltx) if proc.exitcode == 0: if "<merror>" in proc.stdout: raise Exception else: return proc.stdout else: raise Exception
def get_image_link(self, parent_link, page): node_script = '' while node_script is '': node_script = self.get_data(self.general_formula % (parent_link, parent_link[2:-1], page), 'http://www.dm5.com%s' % parent_link).decode('utf-8') if node_script is '': webbrowser.open_new('http://www.dm5.com%s' % parent_link) time.sleep(3) refined_script = 'process.stdout.write(' + node_script.strip() + '+\'\\n\')' with open('towards_direct_link.js', 'w') as file: file.write(refined_script) from Naked.toolshed.shell import muterun_js response = muterun_js('towards_direct_link.js') stdout = response.stdout.decode('utf-8') return stdout.split(',')[0]
def event_run(args): ''' Node.js wrapper function. Calls event.js with the provided args. ''' print 'event_run' response = muterun_js('pf_api/event.js', args) if response.exitcode == 0: # print response.stdout # all went well, create python object with the returned json loaded_json = json.loads(response.stdout) else: print 'args = ', args print 'response.stdout = ', response.stdout print 'response.stderr = ', response.stderr return 'response.stdout = ', response.stdout return loaded_json
def completeinsert(): issueurl= 'http://testnet.api.coloredcoins.org:80/v3/issue' funded_address='moXvpRmNQXkfpggXmQGvE3gbp3QyM9cpdq' assetin= { 'issueAddress': 'moXvpRmNQXkfpggXmQGvE3gbp3QyM9cpdq', 'amount': 1, 'divisibility': 0, 'fee': 5000, 'reissueable':'false', } r=requests.post(issueurl,data=assetin) reply=r.json() issuehash=reply['txHex'] asset=reply['assetId'] response=muterun_js("sign_transaction.js",issuehash) regex=r"\[(.*?)\]" matchobj=re.search(regex,response.stdout) broadcast(matchobj.group(1)) print(asset)
def call(self, method, view, context={}): self.view = view self.context = context self.args = {} self.args['file'] = "/tmp/manana-{0}".format(str(randint(100000, 999999))) self.args['interpreter'] = self.interpreter self.args['view_dir'] = self.view_dir self.args['view'] = self.view self.args['context'] = self.context self.args['method'] = method args = json.dumps(self.args) with open(self.args['file'], 'w') as f: f.write(args) self.response = muterun_js(self.node_wrapper, self.args['file']); if self.response.exitcode == 0: self.output = self.response.stdout return self.output else: raise MananaException(self.response.stderr)
def renderRequest(request): # Pull json out of request object, parse as JSON req = json.loads(request.form["data"]) # Pull template name request template = req["template"] ## get intermediary processing script specific for this template` intermediary = imp.load_source('intermediary', 'scripts/intermediate/'+template+'.py') # pull extra information from intermediary script # - this should be data that will need lookups, but won't be included in the request from CKAN (ie, town hall address for CERC Town Profiles) info = intermediary.get_info(req) # config options should be passed in to the request as part of the json - under "config" - and should be an object of key:value pairs # other config options (such as color schemes) will be loaded dynamically from static json files that share a name with the template templateConfig = {} if (path.isfile(path.join("static", template+".json"))): templateConfig = json.load(open(path.join("static", template+".json"))) # Add any template-level config params from request templateConfig.update(req["config"]) # Get extra objects - ones that will be present for all requests for this template that don't need to be included in the json passed in through POST # ie. CERC Town Profiles - the map in the header req["objects"].extend(intermediary.get_extra_obj(req)) # build vis objects objects = {} for requestObj in req["objects"]: obj = {} # Every intermediary script should have one transformation method for each type of viz [pie, map, bar, table] requestObj = intermediary.transformations[requestObj["type"]](requestObj) # take a copy of the template-level config and update with visualization-level configs for this object config = templateConfig.copy() config.update(requestObj["config"]) ## This is as clean as can be right now. We need either ## a) a way to turn a dictionary into CL args ie ## {"data" : quote(json.dumps(requestObj["data"])), "config" : quote(json.dumps(config))} -> "--data=stuff --config=things" ## or ## b) A class for creating our node calls, probably preferable and neater, easier to maintain etc. clScript = "scripts/visualizations/"+requestObj["type"]+".js" clData = "--data="+quote(json.dumps(requestObj["data"])) clConfig = "--config="+quote(json.dumps(config)) nodeResponse = muterun_js(clScript, clData+" "+clConfig) # # Useful debugging - change if clause to be whatever type of chart you're debugging # if(requestObj['type'] == "table"): # print("###############") # print(requestObj["name"]) # print("###############") # print(nodeResponse.stdout) # print(nodeResponse.stderr) # print(nodeResponse.exitcode) obj["output"] = render_template(requestObj["type"]+".html", data = nodeResponse.stdout) obj["className"] = requestObj["type"]; obj["config"] = requestObj["config"]; obj["dump"] = nodeResponse.stdout obj["data"] = requestObj["data"] objects[requestObj["name"]] = obj # render template response = render_template(template+".html", config = templateConfig, info = info, objects = objects) return response
from Naked.toolshed.shell import muterun_js response = muterun_js('scripts/crash.js') print 'Done script with result: %s' % response.exitcode if response == 0: # this should not happend print 'We should continue the next script' else: print 'The script exit with crash code, we should stop here'
group_id="my_consumer_group", auto_commit_enable=True, auto_commit_interval_ms=30 * 1000, auto_offset_reset="smallest", ) from kafka import SimpleProducer, KafkaClient # To send messages synchronously kafka = KafkaClient(["52.4.219.61:9092", "54.164.200.26:9092", "54.152.210.81:9092"]) producer = SimpleProducer(kafka) # Infinite iteration for m in consumer: name = "task33.json" # Name of text file coerced with +.txt try: file = open(name, "w+") # Trying to create a new file or open one file.write(str(m.value)) file.close() except: print ("Something went wrong! Can't tell what?") sys.exit(0) # quit Python response = muterun_js("server task33") if response.exitcode == 0 and len(response.stdout) > 0: print ("&&" + response.stdout + "&&") li = json.loads(response.stdout) for item in li: print item["task"] print json.dumps(item) producer.send_messages(bytes(item["task"] + "2"), bytes(json.dumps(item)))
def test_muterun_node_success(self): out = muterun_js(self.node_success_path) self.assertEqual(b'success\n', out.stdout) self.assertEqual(0, out.exitcode) self.assertEqual(b'', out.stderr)
def fg_make_prob(situation): args = ' '.join("--%s=%r" % (key,val) for (key,val) in situation.iteritems()) model_fg = muterun_js('model-fg/model-fg.js', args) return model_fg.stdout.split()[-1]
bootstrap_servers=["52.4.219.61:9092","54.164.200.26:9092","54.152.210.81:9092"], group_id='my_consumer_group', auto_commit_enable=True, auto_commit_interval_ms=30 * 1000, auto_offset_reset='smallest') from kafka import SimpleProducer, KafkaClient # To send messages synchronously kafka = KafkaClient(["52.4.219.61:9092","54.164.200.26:9092","54.152.210.81:9092"]) producer = SimpleProducer(kafka) # Infinite iteration for m in consumer: name = 'taskss.json' # Name of text file coerced with +.txt try: file = open(name,'w+') # Trying to create a new file or open one file.write(str(m.value)) file.close() except: print('Something went wrong! Can\'t tell what?') sys.exit(0) # quit Python response=muterun_js('server taskss') if response.exitcode==0 and len(response.stdout)>0: print("&&"+response.stdout+"&&") li=(json.loads(response.stdout)) for item in li: print item["task"] print json.dumps(item) producer.send_messages(bytes(item["task"]+"2"), bytes(json.dumps(item)))
def signatransaction(inputstuff): response=muterun_js("sign_transaction.js",inputstuff) regex=r"\[(.*?)\]" matchobj=re.search(regex,response.stdout) print (matchobj.group(1))
def execute_script_silent(self, script_path, *args): result = muterun_js(script_path, self.args_to_string(args)) if result.exitcode == 0: return True else: raise NodeExecutionFailedException(result.stderr)
def execute(self, script, *args): result = muterun_js('-e "' + script + '"', self.args_to_string(args)) if result.exitcode == 0: return result.stdout.decode('utf-8').strip() else: raise NodeExecutionFailedException(result.stderr)
# more advanced consumer -- multiple topics w/ auto commit offset # management consumer = KafkaConsumer('zillowDetail2', bootstrap_servers=["52.4.219.61:9092","54.164.200.26:9092","54.152.210.81:9092"], group_id='my_consumer', auto_commit_enable=True, auto_commit_interval_ms=30 * 1000, auto_offset_reset='smallest') from kafka import SimpleProducer, KafkaClient # To send messages synchronously kafka = KafkaClient(["52.4.219.61:9092","54.164.200.26:9092","54.152.210.81:9092"]) producer = SimpleProducer(kafka) # Infinite iteration for m in consumer: name = 'tasksswwwdsw.json' # Name of text file coerced with +.txt print(json.loads(m.value)["url"]) try: file = open(name,'w+') # Trying to create a new file or open one file.write(str(m.value)) file.close() except: print('Something went wrong! Can\'t tell what?') sys.exit(0) # quit Python response=muterun_js('server tasksswwwdsw') if response.exitcode==0 and len(response.stdout)>0: print("&&"+response.stdout+"&&")
from Naked.toolshed.shell import execute_js, muterun_js response = muterun_js('genseed.js', arguments="hello") print response.stdout print response.stderr #success = execute_js('createasset.js') #if success: # print 'yay' #else: # print 'aww'
def test_muterun_node_fail(self): out = muterun_js(self.node_fail_path) self.assertEqual(b'error\n', out.stderr) self.assertEqual(b'', out.stdout) self.assertEqual(1, out.exitcode)