Skip to content

Instantly share code, notes, and snippets.

@duchenpaul
Created February 11, 2019 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duchenpaul/eaa536c957f324d4352339cab1696abb to your computer and use it in GitHub Desktop.
Save duchenpaul/eaa536c957f324d4352339cab1696abb to your computer and use it in GitHub Desktop.
Extract data from nwqs
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