Exemple #1
0
def poll_feed_sub(mb, sub, config):
    if sub.subscription_type != FEED_SUBSCRIPTION_TYPE:
        return False
    
    # sweet, go ahead...
    client = http.create_client(config)
    try:
        poll_feed(mb, sub, client)
    finally:
        http.close_all(client)
    return True
Exemple #2
0
def _feed_links_html(request, query):
    if query is None:
        return None

    client = http.create_client(request.context.config)
    try:
        headers = {'Connection': 'close'}
        response, content = client.request(query, headers=headers)

        if response.status != 200: 
            return None

        ct = response.get('content-type', '')
        if ';' in ct:
            ct = ct[0:ct.find(';')]
        ct = ct.strip()
        if ct not in HTML_TYPES: 
            return None

        # parse html
        links = []
        parser = html5lib.HTMLParser(tree=treebuilders.getTreeBuilder("etree", etree),
                                     namespaceHTMLElements=False)
        html = parser.parse(content)
        for link in html.find("head").findall("link"):
            if link.get("rel", "").lower() == "alternate":
                linktype = link.get("type", "").lower()
                if linktype in FEED_TYPES:
                    href = link.get("href", "")
                    if href:
                        feed_item = {'url': href, 'title': link.get("title", "")}
                        links.append(feed_item)
        return links
    except:
        log.error("Error finding feed links at %s: %s" % (query, traceback.format_exc()))
        return None
    finally:
        http.close_all(client)
Exemple #3
0
def _feed_info(request, query):
    if query is None:
        return None

    client = http.create_client(request.context.config)
    try:
        headers = {'Connection': 'close'}
        response, content = client.request(query, headers=headers)

        if response.status != 200: 
            return None

        ff = feedparser.parse(content)
        if ff and 'feed' in ff and 'bozo_exception' not in ff:
            return {'url': query,
                    'title': ff.feed.get('title', '')}
        else:
            return None

    except:
        log.error("Error verifying feed at %s: %s" % (query, traceback.format_exc()))
        return None
    finally:
        http.close_all(client)