Guest User

Untitled

a guest
Nov 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import yaml
  2. from os import listdir
  3. from os.path import join, basename
  4.  
  5. files = listdir("input/")
  6. total_size = str(len(files))
  7. current = 0
  8.  
  9. for unsafe in files:
  10. with open(join("input/", unsafe), 'r') as unsafe:
  11. with open(join("output/", basename(unsafe.name).split(".")[0] + ".clean.yml"), 'w') as out_file:
  12. try:
  13. unsafe_data = yaml.load(unsafe)
  14. safe_data = {}
  15. safe_data['homes'] = unsafe_data.get('homes', [])
  16. safe_data['money'] = unsafe_data.get('money', 0)
  17. safe_data['nickname'] = unsafe_data.get('nickname', "")
  18. yaml.dump(safe_data, out_file, default_flow_style=False)
  19. current += 1
  20. print("Processed " + str(current) + " of " + total_size)
  21. except yaml.YAMLError as ex:
  22. print(ex)
Add Comment
Please, Sign In to add comment