Created
February 11, 2019 04:26
-
-
Save duchenpaul/eaa536c957f324d4352339cab1696abb to your computer and use it in GitHub Desktop.
Extract data from nwqs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import sqlparse | |
import xmltodict | |
from pprint import pprint | |
def xml2dict(xmlString): | |
'''Return json object''' | |
jsonString = json.dumps(xmltodict.parse(xmlString), indent=4) | |
xml_in_dict = json.loads(jsonString) | |
return xml_in_dict | |
nwqs_file = 'file.nwqs' | |
with open(nwqs_file) as f: | |
nwqs_dict = xml2dict(f.read()) | |
for index, data in enumerate(nwqs_dict["QuerySet"]["Query"]): | |
with open('{} {}.sql'.format(index, data["Name"]).replace(' ', '_'), 'w') as f: | |
f.write(sqlparse.format(data["SQL"], reindent=True, keyword_case='upper')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment