예제 #1
0
def construct_article(entry, feed):
    "Safe method to transorm a feedparser entry into an article"
    now = datetime.utcnow()
    date = None
    for date_key in ('published', 'created', 'date'):
        if entry.get(date_key):
            try:
                date = dateutil.parser.parse(entry[date_key])\
                        .astimezone(timezone.utc)
            except Exception:
                pass
            else:
                break

    content = get_article_content(entry)
    link = get_article_link(entry)
    content = clean_urls(content, link)

    return {
        'feed_id': feed['id'],
        'user_id': feed['user_id'],
        'entry_id': extract_id(entry).get('entry_id', None),
        'link': link,
        'content': content,
        'title': html.unescape(entry.get('title', 'No title')),
        'readed': False,
        'like': False,
        'retrieved_date': now,
        'date': date or now
    }
예제 #2
0
def construct_article(entry, feed):
    "Safe method to transorm a feedparser entry into an article"
    now = datetime.utcnow()
    date = None
    for date_key in ('published', 'created', 'date'):
        if entry.get(date_key):
            try:
                date = dateutil.parser.parse(entry[date_key])\
                        .astimezone(timezone.utc)
            except Exception:
                pass
            else:
                break

    content = get_article_content(entry)
    link = get_article_link(entry)
    content = clean_urls(content, link)

    return {'feed_id': feed['id'],
            'user_id': feed['user_id'],
            'entry_id': extract_id(entry).get('entry_id', None),
            'link': link, 'content': content,
            'title': html.unescape(entry.get('title', 'No title')),
            'readed': False, 'like': False,
            'retrieved_date': now, 'date': date or now}
예제 #3
0
파일: home.py 프로젝트: jaesivsm/JARR
def get_article(article_id, parse=False):
    locale = get_locale()
    contr = ArticleController(current_user.id)
    article = contr.get(id=article_id)
    if not article.readed:
        article['readed'] = True
        contr.update({'id': article_id}, {'readed': True})
    article['category_id'] = article.category_id or 0
    feed = FeedController(current_user.id).get(id=article.feed_id)
    article['icon_url'] = url_for('icon.icon', url=feed.icon_url) \
            if feed.icon_url else None
    readability_available = bool(current_user.readability_key
                                 or conf.PLUGINS_READABILITY_KEY)
    article['date'] = format_datetime(localize(article.date), locale=locale)
    article['readability_available'] = readability_available
    if parse or (not article.readability_parsed
            and feed.readability_auto_parse and readability_available):
        try:
            new_content = readability.parse(article.link,
                    current_user.readability_key
                    or conf.PLUGINS_READABILITY_KEY)
        except Exception as error:
            flash("Readability failed with %r" % error, "error")
            article['readability_parsed'] = False
        else:
            article['readability_parsed'] = True
            article['content'] = clean_urls(new_content, article['link'])
            new_attr = {'readability_parsed': True, 'content': new_content}
            contr.update({'id': article['id']}, new_attr)
    return article
예제 #4
0
파일: home.py 프로젝트: v-khdumi/JARR
def get_article(article_id, parse=False):
    locale = get_locale()
    contr = ArticleController(current_user.id)
    article = contr.get(id=article_id)
    if not article.readed:
        article['readed'] = True
        contr.update({'id': article_id}, {'readed': True})
    article['category_id'] = article.category_id or 0
    feed = FeedController(current_user.id).get(id=article.feed_id)
    article['icon_url'] = url_for('icon.icon', url=feed.icon_url) \
            if feed.icon_url else None
    readability_available = bool(current_user.readability_key
                                 or conf.PLUGINS_READABILITY_KEY)
    article['date'] = format_datetime(localize(article.date), locale=locale)
    article['readability_available'] = readability_available
    if parse or (not article.readability_parsed and feed.readability_auto_parse
                 and readability_available):
        try:
            new_content = readability.parse(
                article.link, current_user.readability_key
                or conf.PLUGINS_READABILITY_KEY)
        except Exception as error:
            flash("Readability failed with %r" % error, "error")
            article['readability_parsed'] = False
        else:
            article['readability_parsed'] = True
            article['content'] = clean_urls(new_content, article['link'])
            new_attr = {'readability_parsed': True, 'content': new_content}
            contr.update({'id': article['id']}, new_attr)
    return article