Skip to content

Instantly share code, notes, and snippets.

@markwalkom
Created December 15, 2018 07:52
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 markwalkom/beb9ceaf42da9cb985c9316998e6a4e1 to your computer and use it in GitHub Desktop.
Save markwalkom/beb9ceaf42da9cb985c9316998e6a4e1 to your computer and use it in GitHub Desktop.
from ftplib import FTP
import os
import xml.etree.ElementTree as ET
import xmltodict
import json
url = 'ftp.bom.gov.au'
filename = 'IDN65068.xml'
def writeline(data):
filedata.write(data)
filedata.write(os.linesep)
ftp = FTP(url)
ftp.login()
ftp.cwd('/anon/gen/fwo/')
filedata = open(filename, 'w')
ftp.retrlines('RETR %s' % filename, writeline)
filedata.close()
ftp.quit()
f = open(filename)
XML_content = f.read()
x = xmltodict.parse(XML_content)
j = json.dumps(x)
filename = filename.replace('.xml', '')
output_file = open(filename + '.json', 'w')
output_file.write(j)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment