Created
December 15, 2018 07:52
-
-
Save markwalkom/beb9ceaf42da9cb985c9316998e6a4e1 to your computer and use it in GitHub Desktop.
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
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