convertCurrency.py 1.1 KB

1234567891011121314151617181920212223242526272829
  1. import json
  2. import xmltodict
  3. with open("iso4217.xml") as xml_file:
  4. data_dict = xmltodict.parse(xml_file.read())
  5. xml_file.close()
  6. array_of_currencies = data_dict["ISO_4217"]["CcyTbl"]["CcyNtry"]
  7. formatted_currency_dict = {}
  8. for currency_dict in array_of_currencies:
  9. if ("Ccy" in currency_dict) and ("CcyMnrUnts" in currency_dict):
  10. currency_code = currency_dict["Ccy"]
  11. currency_minor_units = currency_dict["CcyMnrUnts"]
  12. if currency_minor_units == "N.A.":
  13. print("No minor units data available for " + currency_dict["CtryNm"])
  14. else:
  15. formatted_currency_dict[currency_code] = int(currency_minor_units)
  16. elif ("CtryNm" in currency_dict):
  17. print("No currency data available for " + currency_dict["CtryNm"])
  18. else:
  19. print("Currency in file with no data at all, weird.")
  20. json_data = json.dumps(formatted_currency_dict)
  21. with open("../../Runtime/Resources/iso4217.json", "w") as json_file:
  22. json_file.write(json_data)
  23. json_file.close()