async def fetch_event(url: URL) -> Optional[Event]: """ Extract a event from a page. We assume the event is represented as an h-event in the URL. """ async with ClientSession() as session: async with session.get(url) as response: content = await response.text() parser = mf2py.Parser(content) hevents = parser.to_dict(filter_by_type="h-event") if not hevents: _logger.warning("No events found on %s", url) return None if len(hevents) > 1: _logger.warning("Multiple events found on %s", url) return None hevent = hevents[0] event = Event() event.add("summary", hevent["properties"]["name"][0]) event.add("dtstart", dateutil.parser.parse(hevent["properties"]["start"][0])) event.add("dtend", dateutil.parser.parse(hevent["properties"]["end"][0])) event.add("dtstamp", datetime.now(timezone.utc)) if "url" in hevent["properties"]: event.add("url", hevent["properties"]["url"][0]) if "content" in hevent["properties"]: event.add("description", hevent["properties"]["content"][0]["value"]) if "category" in hevent["properties"]: event.add("categories", hevent["properties"]["category"]) if "featured" in hevent["properties"]: attachment_url = url.join(URL(hevent["properties"]["featured"][0])) event.add("attach", attachment_url) return event
def xform_instance_to_dict(xml_str, data_dictionary): parser = XFormInstanceParser(xml_str, data_dictionary) return parser.to_dict()
def xform_instance_to_dict(xml_str, data_dictionary): parser = XFormInstanceParser(xml_str, data_dictionary) return parser.to_dict()