Guest User

Untitled

a guest
Dec 15th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. from ftplib import FTP
  2. import os
  3. import xml.etree.ElementTree as ET
  4. import xmltodict
  5. import json
  6.  
  7. url = 'ftp.bom.gov.au'
  8. filename = 'IDN65068.xml'
  9.  
  10. def writeline(data):
  11. filedata.write(data)
  12. filedata.write(os.linesep)
  13.  
  14. ftp = FTP(url)
  15. ftp.login()
  16. ftp.cwd('/anon/gen/fwo/')
  17. filedata = open(filename, 'w')
  18. ftp.retrlines('RETR %s' % filename, writeline)
  19. filedata.close()
  20.  
  21. ftp.quit()
  22.  
  23. f = open(filename)
  24. XML_content = f.read()
  25.  
  26. x = xmltodict.parse(XML_content)
  27. j = json.dumps(x)
  28.  
  29. filename = filename.replace('.xml', '')
  30. output_file = open(filename + '.json', 'w')
  31. output_file.write(j)
Add Comment
Please, Sign In to add comment