Пример #1
0
def response(resp):
    results = []

    rss = etree.fromstring(resp.content)

    ns = rss.nsmap

    # parse results
    for item in rss.xpath('./channel/item'):
        # url / title / content
        url = url_cleanup(item.xpath('./link/text()')[0])
        title = list_get(item.xpath('./title/text()'), 0, url)
        content = list_get(item.xpath('./description/text()'), 0, '')

        # publishedDate
        publishedDate = list_get(item.xpath('./pubDate/text()'), 0)
        try:
            publishedDate = parser.parse(publishedDate, dayfirst=False)
        except TypeError:
            publishedDate = datetime.now()
        except ValueError:
            publishedDate = datetime.now()

        # thumbnail
        thumbnail = list_get(item.xpath('./News:Image/text()', namespaces=ns),
                             0)
        if thumbnail is not None:
            thumbnail = image_url_cleanup(thumbnail)

        # append result
        if thumbnail is not None:
            results.append({
                'template': 'videos.html',
                'url': url,
                'title': title,
                'publishedDate': publishedDate,
                'content': content,
                'thumbnail': thumbnail
            })
        else:
            results.append({
                'url': url,
                'title': title,
                'publishedDate': publishedDate,
                'content': content
            })

    # return results
    return results
Пример #2
0
def response(resp):
    results = []

    dom = html.fromstring(resp.text)

    # parse results
    for result in dom.xpath(results_xpath):
        videoid = list_get(result.xpath('@data-context-item-id'), 0)
        if videoid is not None:
            url = base_youtube_url + videoid
            thumbnail = 'https://i.ytimg.com/vi/' + videoid + '/hqdefault.jpg'

            title = extract_text_from_dom(result, title_xpath) or videoid
            content = extract_text_from_dom(result, content_xpath)

            embedded = embedded_url.format(videoid=videoid)

            # append result
            results.append({'url': url,
                            'title': title,
                            'content': content,
                            'template': 'videos.html',
                            'embedded': embedded,
                            'thumbnail': thumbnail})

    # return results
    return results
Пример #3
0
def response(resp):
    results = []

    dom = html.fromstring(resp.text)

    # parse results
    for result in dom.xpath(results_xpath):
        videoid = list_get(result.xpath('@data-context-item-id'), 0)
        if videoid is not None:
            url = base_youtube_url + videoid
            thumbnail = 'https://i.ytimg.com/vi/' + videoid + '/hqdefault.jpg'

            title = extract_text_from_dom(result, title_xpath) or videoid
            content = extract_text_from_dom(result, content_xpath)

            embedded = embedded_url.format(videoid=videoid)

            # append result
            results.append({
                'url': url,
                'title': title,
                'content': content,
                'template': 'videos.html',
                'embedded': embedded,
                'thumbnail': thumbnail
            })

    # return results
    return results
Пример #4
0
def response(resp):
    results = []

    rss = etree.fromstring(resp.content)

    ns = rss.nsmap

    # parse results
    for item in rss.xpath('./channel/item'):
        # url / title / content
        url = url_cleanup(item.xpath('./link/text()')[0])
        title = list_get(item.xpath('./title/text()'), 0, url)
        content = list_get(item.xpath('./description/text()'), 0, '')

        # publishedDate
        publishedDate = list_get(item.xpath('./pubDate/text()'), 0)
        try:
            publishedDate = parser.parse(publishedDate, dayfirst=False)
        except TypeError:
            publishedDate = datetime.now()
        except ValueError:
            publishedDate = datetime.now()

        # thumbnail
        thumbnail = list_get(item.xpath('./News:Image/text()', namespaces=ns), 0)
        if thumbnail is not None:
            thumbnail = image_url_cleanup(thumbnail)

        # append result
        if thumbnail is not None:
            results.append({'template': 'videos.html',
                            'url': url,
                            'title': title,
                            'publishedDate': publishedDate,
                            'content': content,
                            'thumbnail': thumbnail})
        else:
            results.append({'url': url,
                            'title': title,
                            'publishedDate': publishedDate,
                            'content': content})

    # return results
    return results