-
-
Save tmc/2582615 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project-report> | |
<project-name>lab5</project-name> **Required | |
<upload-date>NONE</upload-date> **Required | |
<upload-updated>NONE</upload-updated> **Required | |
<due-date>2011-10-20 00:00:00</due-date> **Required | |
<section-name>W</section-name> **Required | |
<grader-name>GRADER_Last</grader-name> **Required | |
<student-info> **Required | |
<student-name>Barish,David</student-name> **Required | |
<student-kuid>3450008</student-kuid> **Required | |
</student-info> | |
<grade-criteria> **Required | |
<stacks awarded_pts="7" max_pts="7">None</stacks> **For all of the grade criteria, must have awarded and max pt attributes | |
<queues awarded_pts="7" max_pts="7">None</queues> **but the element name and number of elements is arbitrary | |
<linked_lists awarded_pts="10" max_pts="10">For the destructor, you can just call remove(0) while is_empty returns false.</linked_lists> | |
<command_logic awarded_pts="18" max_pts="18">None</command_logic> | |
<style_output awarded_pts="9" max_pts="9">None</style_output> | |
<documentation awarded_pts="9" max_pts="9">None</documentation> | |
<total awarded_pts="1" max_pts="60">None</total> | |
</grade-criteria> | |
<penalty percent="0">None</penalty> **Required | |
<comments>Great Project </comments> **Required | |
<!--NO - Not Ready, READY - Ready to send, SENT - Sent to student--> | |
<email-status>NO</email-status> **Required | |
</project-report> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from lxml import etree, objectify | |
class ProjectReport(etree.ElementBase): | |
@classmethod | |
def fromstring(cls, input_string): | |
pr = cls() | |
o = pr._o = objectify.fromstring(input_string) | |
pr.name = o['project-name'] | |
pr.upload_date = o['upload-date'] | |
pr.upload_updated = o['upload-updated'] | |
pr.due_date = o['due-date'] | |
pr.section_name = o['section-name'] | |
pr.grader_name = o['grader-name'] | |
pr.student = (o['student-info']['student-kuid'], o['student-info']['student-name']) | |
pr.grades = [(el.tag, el.attrib) for el in o['grade-criteria'].getchildren()] | |
pr.penalty = o.penalty.get('percent') | |
pr.comments = o.comments | |
pr.email_status = o['email-status'] | |
return pr | |
if __name__ == '__main__': | |
p = ProjectReport.fromstring(open('input.xml').read()) | |
print p | |
print p.__dict__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment