from config import *
import xmltodict
import json

#xml_file_path = "metadata.xml"
#json_file_path = "xmlmetadata.json"

def getJsonPath(xmlPath):
    xmlPath = xmlPath.split('xml')
    jsonpath = xmlPath[0] + 'json'
    return jsonpath

def convertXml2JsonfromPathArray(pathArray):
    for path in pathArray:
        convertXml2JsonFromPath(path)


def convertXml2JsonFromPath(xml_file_path):
    with open(xml_file_path) as input_file:
        my_xml = xmltodict.parse(input_file.read(), process_namespaces=True)
        json_file_path = getJsonPath(xml_file_path)
        with open(json_file_path, 'w') as output_file:
            json.dump(my_xml, output_file, indent=4)

if __name__ == '__main__':
    convertXml2JsonfromPath(NEW_ETDs_UPLOAD_PATH)
