def get_employees(self): with open(self.filename) as xml_file: self.logger.info('reading XML data from %s', self.filename) converter = xml2json(self.filename) data = json.loads(converter.get_json()) self.logger.info('reading XML data: done') return data["root"]["employees"]["element"]
def run_xml2json(): print """xml2json by Kailash Nadh (http://nadh.in) --help for help """ # parse arguments parser = argparse.ArgumentParser( description='Convert an xml file to json.') parser.add_argument('--input', type=file, dest='input_file', required=True, help='input xml filename') parser.add_argument('--output', dest='output_file', required=True, help='output json filename') parser.add_argument('--pretty', dest='pretty', required=False, default=False, action='store_true', \ help='pretty print? (default=False)') parser.add_argument('--encoding', dest='encoding', default='utf-8', help='character encoding (default=utf-8)') args = parser.parse_args() converter = xml2json(args.input_file, args.output_file, args.encoding) num = converter.convert(pretty=args.pretty) print "Wrote to", args.output_file
def run_xml2json(): print """xml2json by Kailash Nadh (http://nadh.in) --help for help """ # parse arguments parser = argparse.ArgumentParser(description="Convert an xml file to json.") parser.add_argument("--input", type=file, dest="input_file", required=True, help="input xml filename") parser.add_argument("--output", dest="output_file", required=True, help="output json filename") parser.add_argument( "--pretty", dest="pretty", required=False, default=False, action="store_true", help="pretty print? (default=False)", ) parser.add_argument("--encoding", dest="encoding", default="utf-8", help="character encoding (default=utf-8)") args = parser.parse_args() converter = xml2json(args.input_file, args.output_file, args.encoding) num = converter.convert(pretty=args.pretty) print "Wrote to", args.output_file
def x(a,b,c,i): converter = xml2json(a,b,encoding=c) converter.convert() f2=open ('D:/triposo/samp2'+str(i)+'.json','r') finaljson1=f2.read() f2.close() #print finaljson1 final.append(finaljson1)
def x(a,b,c,i): converter = xml2json(a,b,encoding=c) converter.convert() f2=open ('/home/dell1/Documents/Crayon/samp'+str(i)+'.json','r') finaljson1=f2.read() f2.close() #print finaljson1 final.append(finaljson1)
def parse_xml(xml): print 'parse_xml:' try: xml = json.loads(xml2json.xml2json(io.StringIO(xml)).get_json()) except: return None result = None if 'unitellerresult' in xml: # Uniteller uni_result=xml['unitellerresult'] pprint(uni_result) order = uni_result['orders']['order'] dt = datetime.datetime.strptime(order['date'], '%d.%m.%Y %H:%M:%S') order['date'] = dt.strftime('%Y-%m-%d %H:%M:%S') result = { 'type' : 'uniteller', 'shop_id' : uni_result['request']['shop_id'], 'order_id' : order['ordernumber'], 'sum' : order['total'], 'date' : order['date'], 'response_code' : order['response_code'], 'description' : order['recommendation'], 'approval_code' : order['approvalcode'], 'phone' : order['phone'], 'uni_billnumber' : order['billnumber'], 'status' : order['status'], 'need_confirm' : order['need_confirm'] } elif 'request' in xml: # Platron platron_res=xml['request'] pprint(platron_res) result = { 'type' : 'platron', 'shop_id' : '00006866', 'order_id' : platron_res['pg_order_id'], 'sum' : platron_res['pg_amount'], 'date' : platron_res['pg_payment_date'], 'phone' : platron_res['pg_user_phone'], 'uni_billnumber' : platron_res['pg_payment_id'], 'status' : platron_res['pg_result'], 'can_reject' : platron_res['pg_can_reject'], 'approval_code' : '', 'salt' : platron_res['pg_salt'], 'sig' : platron_res['pg_sig'], } else: return None if not match_code(result['approval_code']): result['approval_code'] = get_code(result['order_id']) # if not result['approval_code']: # if result['type'] == 'platron' and result['status'] == 1: # result['approval_code'] = new_code() return result
def uploaded_file_tojson(f): if f.name.split('.')[1] == 'xml': try: converter = xml2json(f, encoding="utf-8") json=converter.get_json() except: json={"input":"input file type not .xml"} path = default_storage.save(dir_to_file, ContentFile(json)) return path.split('file_')[1] if f.name.split('.')[1] == 'csv': path = default_storage.save(dir_to_file, f) return path.split('file_')[1]
def get_mta_info(): response = requests.get(os.environ["MTA_URI"]) with tempfile.NamedTemporaryFile("w", delete=False) as f: f.file.write(response.content) converter = xml2json(f.name, encoding="utf-8") mta_info = json.loads(converter.get_json()) name = f.name os.remove(name) lines_info = { line["name"]: line["status"] for line in mta_info["service"]["subway"]["line"] if line["name"] in LINES} lines_str = ", ".join(["{}: {}".format(li[0], li[1].title()) for li in lines_info.items()]) print lines_str if os.environ.get("BLOCK_BUTTON"): _ = subprocess.Popen(["chromix", "load", "http://www.mta.info"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def run_xml2json(): print """xml2sql by Kailash Nadh (http://nadh.in) --help for help """ # parse arguments parser = argparse.ArgumentParser(description='Convert an xml file to sql.') parser.add_argument('--input', type=file, dest='input_file', required=True, help='input xml filename') parser.add_argument('--output', dest='output_file', required=True, help='output sql filename') parser.add_argument('--pretty', dest='pretty', required=False, default=False, action='store_true', \ help='pretty print? (default=False)') parser.add_argument('--encoding', dest='encoding', default='utf-8', help='character encoding (default=utf-8)') args = parser.parse_args() converter = xml2json(args.input_file, args.output_file, args.encoding) num = converter.convert(pretty=args.pretty) print "Wrote to", args.output_file
def parse_refund_xml(xml): print 'parse_xml:' try: xml = json.loads(xml2json.xml2json(io.StringIO(xml)).get_json()) except: return None result = None if 'request' in xml: # Platron platron_res=xml['request'] pprint(platron_res) result = { 'type' : 'platron', 'shop_id' : '00006866', 'order_id' : platron_res['pg_order_id'], 'sum' : platron_res['pg_amount'], 'date' : platron_res['pg_refund_date'], 'refund_id' : platron_res['pg_refund_id'], 'salt' : platron_res['pg_salt'], 'sig' : platron_res['pg_sig'], } else: return None return result
__author__ = 'ROHIT' from xmlutils.xml2json import xml2json converter = xml2json("student.xml", encoding="utf-8") fjson = open("student.json", "w") fjson.write(converter.get_json(pretty=True)) fjson.close()
__author__ = 'Venkat Nirmal' from xmlutils.xml2json import xml2json converter = xml2json("Converted_Student_xml.xml", encoding="utf-8") fjson = open("Converted_Student_JSON.json","w") fjson.write(converter.get_json(pretty=True)) fjson.close()
#!/usr/bin/env python import os from xmlutils.xml2json import xml2json # each of the split-up xml files in the current directory, which start with "xx" are converted to json for file in os.listdir("."): if file.startswith("xx"): converter = xml2json(file, encoding="utf-8") print converter.get_json(pretty=False)
def inputToJson(): input_raw = xml2json("/input/hortemotun", encoding ="utf-8") return input_raw.get_json().replace("http://tmix.se/ws/ti", "")
__author__ = 'SANTHOSH' from xmlutils.xml2json import xml2json converter = xml2json("a2.xml", encoding="utf-8") fjson = open("a2.json","w") fjson.write(converter.get_json(pretty=True)) fjson.close()
__author__ = 'ROHIT' from xmlutils.xml2json import xml2json converter = xml2json("student1.xml", encoding="utf-8") fjson = open("student.json","w") 'sorted(converter.get_json())' fjson.write(converter.get_json(pretty=True)) fjson.close()
__author__ = 'SANTHOSH' from xmlutils.xml2json import xml2json converter = xml2json("a2.xml", encoding="utf-8") fjson = open("a2.json", "w") fjson.write(converter.get_json(pretty=True)) fjson.close()