The little things give you away... A collection of various small helper stuff
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ia-files-xml-to-jsonl 622 B

1234567891011121314151617
  1. #!/usr/bin/env python3
  2. import json
  3. import sys
  4. import xml.etree.ElementTree
  5. root = xml.etree.ElementTree.fromstring(sys.stdin.read())
  6. assert root.tag == 'files'
  7. for file in root:
  8. assert file.tag == 'file'
  9. attributes = file.attrib
  10. childrenTags = [child.tag for child in file]
  11. assert sorted(childrenTags) == sorted(set(childrenTags)), 'duplicate children'
  12. children = {child.tag: child.text for child in file}
  13. assert not any(k in children for k in attributes), 'attribute found in children'
  14. assert not any(k in attributes for k in children), 'child found in attributes'
  15. print(json.dumps({**attributes, **children}))