Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Add Comment
Please, Sign In to add comment