Beispiel #1
0
def get_all_events(res):
    if res.status_code != 200: return []

    sio = StringIO(res.text)
    tree = ElementSoup.parse(sio)
    event_nodes = tree.xpath(NODE_XPATH)
    return map(parse_event, event_nodes)
Beispiel #2
0
def get_link_content(url, original_description):
    try:
        site = urlopen(url)
    except Exception:
        return original_description + "\n<p><b>WarGod error</b>: I could not access this url</p>"
    site_url = "/".join(site.geturl().split("/")[:3]) + "/"
    content = site.read()
    try:
        xml = ElementSoup.parse(StringIO(Document(content).summary()))
    except Unparseable:
        return original_description + "\n<p><b>WarGod error</b>: I could not parse this url</p>"
    xml.make_links_absolute(site_url)
    if not xml.find("body") is None:
        return etree.tostring(xml.find("body"), encoding="Utf-8")[6:-7].decode("Utf-8")
    else:
        return ""