def main(): args = sys.argv if not validate_command_line_args(args): return json_file_name = args[1] if len(args) == 2: generate_png = False png_file_name = None else: generate_png = True png_file_name = args[3] try: data_to_draw = JsonParser(json_file_name) except IOError as err: print(err) return palette = Palette(data_to_draw.get_palette()) screen = Screen(data_to_draw.get_screen()) figures = [] for figure in data_to_draw.get_figures(): try: figures.append(create_figure_obj(figure)) except Exception as err: print(err) canvas = PyGameCanvas(palette, screen, figures) canvas.run_pygame(generate_png, png_file_name) return
def get_table_headers(table_name): """ This method is being used to get the header details from JSON config file for a given table :param table_name: Table name to get metadata from config file :return: headers """ json_config_obj = JsonParser() config_list = json_config_obj.read_json(table_name) header_list = [] for i in range(0, len(config_list), 2): attr_1 = config_list[i] header_list.append(attr_1) headers = ','.join(header_list) return header_list
def get_provider_details(table_name): """ This method is being used to get the provider details for each column from JSON config file for a given table :param table_name: Table name to get metadata from config file :return: providers """ json_config_obj = JsonParser() config_list = json_config_obj.read_json(table_name) provider_list = [] for i in range(0, len(config_list), 2): list_attr = config_list[i + 1] provider_list.append(list_attr) providers = ','.join(provider_list) return providers
def fun1(): parser.loads('{"a": "\\u7f51\\u6613CC\\"\'"}') # parser.loads('{ "{ab" : "}123", "\\\\a[": "]\\\\"}') parser.dump_file(file_path) print parser.dumps() parser2 = JsonParser() parser.load_file(file_path) print parser.dumps()
def displayfav(): token = request.args.get('tokenId') req = Request() db = DataBase() id_list = db.get_fav_id(token) response_dict = [] for id in id_list: req.create_fav_request(id) try: req.send_request() except HTTPError: # it might happen that queue id already # doesn't exist. Skip this record and # remove it from the database db.remove_fav(token, id) # skip processing continue jp = JsonParser(req.rec_response()) jp.parse_id_response() response_dict.extend(jp.response) return jsonify(response_dict)
def get(): # print(request.args) region = request.args.get('r_region') case = request.args.get('r_case') benefit = request.args.get('r_benefit') number = request.args.get('r_number') location = request.args.get('r_location') token = request.args.get('r_token') # print('*****', token) req = Request() req.create_request(region, benefit, case, number, location) req.send_request() jp = JsonParser(req.rec_response()) jp.parse(token) status_code = Response(status=200) if token: try: db = DataBase() db.add_to_history(token, region, benefit, case, number, location) except Exception as e: print('error while adding history row:' + str(e)) pass # print(jp.response) return jsonify(jp.response)
class IO: def __init__(self): self.parser = JsonParser() self.text = '' self.read_text() def read_text(self): with open('timetable.json', 'r', encoding='utf-8') as file: self.text = file.read() def get_input_timetable(self): return self.parser.parse(self.text) def get_input_timetable_by_loads(self): return json.loads(self.text) def single_speed_test(self, parse_function, number: int = 1000): start_time = datetime.now() for i in range(number): parse_function() end_time = datetime.now() all_time = (end_time - start_time).total_seconds() return all_time def speed_test(self, number: int = 1000): my_time = self.single_speed_test(self.get_input_timetable, number) lib_time = self.single_speed_test(self.get_input_timetable_by_loads, number) print('my_time:', my_time) print('lib_time:', lib_time) @staticmethod def write_output_timetable(timetable): with open('timetable.serialized', 'wb') as file: file.write(timetable.SerializeToString()) @staticmethod def get_serialized_timetable(): timetable = timetable_pb2.TimeTable() with open('timetable.serialized', 'rb') as file: timetable.ParseFromString(file.read()) return timetable
def upload_file_on_s3(file, file_type='', batch='', table_name=''): """ Uploading the files on S3 buckets :param file: CSV file to be placed on S3 :param file_type: get the path based on file type :return: None """ s3_detail = JsonParser().read_json("bucket_path") s3 = boto3.resource('s3') if file_type is "csv": s3.meta.client.upload_file(file, s3_detail[0], s3_detail[1]+batch+table_name+file) elif file_type is "json": s3.meta.client.upload_file(file, s3_detail[0], s3_detail[2] + file) elif file_type is "xml": s3.meta.client.upload_file(file, s3_detail[0], s3_detail[3] + file) else: print("File cannot be uploaded")
from jsonparser import JsonParser j1 = JsonParser()
raise ValueError("ERROR: Try to send an empty request") def rec_response(self): return self.response def to_ascii_url(self, text): # remove white spaces around text = text.strip() #remove duplicated spaces text = " ".join(text.split()) # replace spaces by '%20' text = text.replace(" ", "%20") # strip right non ascii characters # urllib cant send utf-8 characters and # host doesn't 'understand' encoded ones for c in range(len(text)): if ord(text[c]) >= 128: return text[:c] return text # for testing purposes if __name__ == "__main__": reqiest = Request() reqiest.create_request('01', 'poradnia', 1) reqiest.send_request() from jsonparser import JsonParser jp = JsonParser(reqiest.rec_response()) jp.parse()
def load_python(self, f): ss = f.read() jparser = JsonParser(ss) self._dd = jparser.parse()
def __init__(self): self.parser = JsonParser() self.text = '' self.read_text()
def loads(self, ss): jparser = JsonParser(ss) self._dd = jparser.parse()
('{"a":True}', 1), ('{"a":Null}', 1), ('{"a":foobar}', 2), ("{'a':1}", 3), ('{1:1}', 2), ('{true:1}', 2), ('{"a":{}', 2), ('{"a":-}', 1), ('{"a":[,]}', 2), ('{"a":.1}', 1), ('{"a":+123}', 2), ('{"a":"""}', 1), ('{"a":"\\"}', 1), ] a1 = JsonParser() a2 = JsonParser() a3 = JsonParser() total = 0 expect = 0 errors = [] for s, score in chain(json_ok, json_ex): expect += score try: dst = json.loads(s) except Exception: dst = Exception try: a1.loads(s)
from jsonparser import JsonParser parser = JsonParser() file_path = 'tmp_output_file.txt' def fun1(): parser.loads('{"a": "\\u7f51\\u6613CC\\"\'"}') # parser.loads('{ "{ab" : "}123", "\\\\a[": "]\\\\"}') parser.dump_file(file_path) print parser.dumps() parser2 = JsonParser() parser.load_file(file_path) print parser.dumps() def fun2(): s = '{ "{ab" : "}123", "\\\\a[": "]\\\\"}' # print s[20] for i, j in enumerate(s): print i, j if __name__ == '__main__': fun1() #fun2()