def get_crime_entries_from_dom(self, dom, sort=True): """ get a list of CrimeEntry objects from the dom """ entries = [] for entry in dom.getElementsByTagName("entry"): child = None child_title = None for child in entry.childNodes: if is_dom_element(child): if child.nodeName == 'title': for subchild in child.childNodes: if hasattr(subchild, 'data'): child_title = subchild.data if child.nodeName == 'content': for subchild in child.childNodes: if is_dom_element(subchild): crime_entry = self.get_crime_entry_from_content_node(subchild) if child_title != "": crime_entry.set_title(child_title) entries.append(crime_entry) if sort: entries.sort(key=lambda x: x.get_report_datetime(), reverse=True) return entries
def __get_content_item(self, dom, tag_name): """ Get specific field from CrimeEntry dom """ for child in dom.childNodes: if is_dom_element(child): if child.nodeName == tag_name: for subchild in child.childNodes: if hasattr(subchild, 'data') or hasattr(subchild, 'cdata'): return subchild.data