Advertisement
Guest User

Untitled

a guest
Sep 11th, 2017
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. import xml.etree.ElementTree as ET
  2.  
  3. article_file = "exampleResearchArticle.xml"
  4.  
  5.  
  6. def get_root(fname):
  7. tree = ET.parse(fname)
  8. return tree.getroot()
  9.  
  10.  
  11. def get_authors(root):
  12. authors = []
  13. for author in root.findall('./fm/bibl/aug/au'):
  14. data = {
  15. "fnm": None,
  16. "snm": None,
  17. "email": None
  18. }
  19.  
  20. # YOUR CODE HERE
  21. data["fnm"] = author.find('./fnm').text
  22. data['snm'] = author.find('./snm').text
  23. data['email'] = author.find('./email').text
  24.  
  25.  
  26. authors.append(data)
  27.  
  28. return authors
  29.  
  30.  
  31.  
  32. #def test():
  33. solution = [{'fnm': 'Omer', 'snm': 'Mei-Dan', 'email': 'omer@extremegate.com'}, {'fnm': 'Mike', 'snm': 'Carmont', 'email': 'mcarmont@hotmail.com'}, {'fnm': 'Lior', 'snm': 'Laver', 'email': 'laver17@gmail.com'}, {'fnm': 'Meir', 'snm': 'Nyska', 'email': 'nyska@internet-zahav.net'}, {'fnm': 'Hagay', 'snm': 'Kammar', 'email': 'kammarh@gmail.com'}, {'fnm': 'Gideon', 'snm': 'Mann', 'email': 'gideon.mann.md@gmail.com'}, {'fnm': 'Barnaby', 'snm': 'Clarck', 'email': 'barns.nz@gmail.com'}, {'fnm': 'Eugene', 'snm': 'Kots', 'email': 'eukots@gmail.com'}]
  34.  
  35. root = get_root(article_file)
  36. data = get_authors(root)
  37.  
  38. assert data[0] == solution[0]
  39. assert data[1]["fnm"] == solution[1]["fnm"]
  40.  
  41.  
  42. test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement