def import_run(profile_id, file_name, data): """ Запуск импорта шаблонов """ with tempfile.TemporaryDirectory() as temp_path: uint_8_array_to_file(os.path.join(temp_path, file_name), data) suites = ImportSuite() suite_id = None prev_template = None for template in suites.process(os.path.join(temp_path, file_name)): if prev_template is None and template: # открыли новый файл request_data = create_suite_request_data(profile_id=profile_id) response = post_request(url=GATEWAY_URL, headers=HEADERS, request_data=request_data) suite_id = response["result"]["response"]["id"] prev_template = template if not template: continue request_data = create_template_request_data(suite_id=suite_id, content=template) post_request(url=GATEWAY_URL, headers=HEADERS, request_data=request_data)
def create_new(cls, data, authentication_token): create_droplet_response = utils.post_request("droplets", data, authentication_token) if not create_droplet_response.ok: raise Exception("Droplet Not Successfully Created! Message Returned {0}".format(create_droplet_response.json()["message"])) return cls(create_droplet_response.json()["droplet"], authentication_token)
def json_requests(client, data, url): func_name = inspect.stack()[1][3] headers = {'content-type': 'application/json'} return post_request(client, data=json.dumps(data), url=url, func_name=func_name, headers=headers)
def _execute_droplet_action(self, data): request_response = utils.post_request("droplets/{0}/actions".format(self.id), data, self.authentication_token) if not request_response.ok: raise Exception("Failed on attempt to {0}! See error message: {1}".format(data["type"], request_response.json()["message"])) return request_response
def create_new(cls, name, ip_address, authentication_token): data = {"name": name, "ip_address": ip_address} create_domain_response = utils.post_request("domains", data, authentication_token) if not create_domain_response.ok: raise Exception("Domain not successfully created! See error message: {0}".format(create_domain_response.json()["message"])) return cls(create_domain_response.json()["domain"], authentication_token)
def create_new(cls, key_and_name, authentication_token): create_key_response = utils.post_request("account/keys", key_and_name, authentication_token) if create_key_response.ok: return cls(create_key_response.json()["ssh_key"], authentication_token) else: raise Exception("Could not create ssh key! See error message: {0}".format(create_key_response.json()["message"]))
def import_run(profile_id, file_name, data): """ Запуск импорта словарей """ with tempfile.TemporaryDirectory() as temp_path: uint_8_array_to_file(os.path.join(temp_path, file_name), data) dictionaries = ImportDictionary() for file_name, dictionary in dictionaries.process( os.path.join(temp_path, file_name)): request_data = create_dictionary_request_data( profile_id=profile_id, code=os.path.splitext(_process_filename(file_name))[0], description=file_name, content=dictionary) post_request(url=GATEWAY_URL, headers=HEADERS, request_data=request_data)
def transfer(self, new_region): data = {"type": "transfer", "region": new_region} transfer_region_response = utils.post_request("images/{0}/actions".format(self.id), data, self.authentication_token) if not transfer_region_response.ok: raise Exception("Failed to transfer region of image! See error message: {0}".format(transfer_region_response.json()["message"])) self.regions = [new_region] return Action(transfer_region_response.json()["action"])
def create_new(cls, domain_name, data, authentication_token): create_domain_record_response = utils.post_request("domains/{0}/records" .format(domain_name), data, authentication_token) if not create_domain_record_response.ok: raise Exception("Failed to create domain record! See error message: {0}".format(create_domain_record_response.json()["message"])) domain_record = create_domain_record_response.json()["domain_record"] domain_record["domain_name"] = domain_name return cls(domain_record, authentication_token)
def fork_request(trainerID='5', local=True, destination_dir="."): """ get zipped code bytes data from postgresql, save it in destination_dir """ trainerID = str(trainerID) logging.warning("relna:client:fork forking trainer {}".format(trainerID)) TRAINER_ZIP = "trainer.zip" if local: url = "http://127.0.0.1:5000/fork" else: url = "https://relna-241818.appspot.com/fork" response = utils.post_request(url, {'trainerID': trainerID}) zipped_code_bytes = response.content with open(TRAINER_ZIP, "wb") as f: f.write(zipped_code_bytes) try: os.mkdir(destination_dir) except: pass utils.unzip_trainer(zipped_trainer_filename=TRAINER_ZIP, destination_dir=destination_dir) os.remove("trainer.zip") logging.warning( "relna:client:fork trainer {}, fork successful".format(trainerID))
text = parsed_text.find('ns2:nsteintext').text elif parsed_text.find('nsteintext'): text = parsed_text.find('nsteintext').text elif parsed_text.find('text'): text = parsed_text.find('text').text if tag_cat: true_cat, _ = find_tag(file_text, tag_cat) else: if parsed_text.find('ns2:name'): true_cat, _ = find_tag(file_text, 'ns2:name') if parsed_text.find('category'): true_cat, _ = find_tag(file_text, 'category') full_text = part1 + text + part2 response = post_request(full_text, url, querystring, debug, headers) if response.text: pred_cat, pred_weight = find_tag(response.text, 'category') results[fname] = [text, true_cat, pred_cat, pred_weight] print('Done\n') # CONVERT DICTIONARY TO PANDAS DATAFRAME df_final = pd.DataFrame.from_dict(results, orient='index', columns=[ 'Document', 'True_Category', 'Predicted_Category', 'Predicted_Weight' ]) #DETERMINE THE WAY TO PRINT / SAVE THE RESULTS