Exemplo n.º 1
0
def index():
    sort = None
    if current_user.is_authenticated:
        s = request.args.get("sort", "trending")
        if s == "trending":
            links = trending_links(current_user.subscribed_feed_ids)
            sort = "Trending"
        elif s == "new":
            links = new_links(current_user.subscribed_feed_ids)
            sort = "New"
        else:
            links = best_links(current_user.subscribed_feed_ids, "all")
            sort = "Best"
    else:
        links = trending_links(current_app.config["DEFAULT_FEEDS"])
    count = request.args.get("count", default=None, type=int)
    paginated_ids, has_less, has_more = paginate(links, 20)
    links = Link.by_ids(paginated_ids) if paginated_ids else []
    return render_template(
        "index.html",
        links=links,
        show_logo=True,
        less_links=has_less,
        more_links=has_more,
        title="eSource News",
        sort=sort,
        count=count,
    )
Exemplo n.º 2
0
def get_feed(feed, sort=None):
    """
    Default feed page
    Sort can be specified by user or default to user's preferred sort or to feed default sort
    :param feed: feed
    :param sort: sort
    :return:
    """
    # if (sort is None or sort not in ['trending', 'new', 'best']) and current_user.is_authenticated:
    #    sort = current_user.preferred_sort
    if sort is None:
        sort = feed.default_sort

    ids, has_less, has_more = paginate(
        LinkQuery(feed_id=feed.id, sort=sort).fetch_ids(), 20)
    links = Link.by_ids(ids) if len(ids) > 0 else []

    if sort == "new" and current_user.is_authenticated:
        links = filter(min_score_filter(current_user.p_min_link_score), links)

    feed.links = links
    return render_template("feed.html",
                           feed=feed,
                           less_links=has_less,
                           more_links=has_more,
                           sort=sort)
Exemplo n.º 3
0
def get_feed_rss(feed):
    """
    Returns the feed in rss form
    :param feed: feed
    :return:
    """
    ids, _, _ = paginate(
        LinkQuery(feed_id=feed.id, sort="trending").fetch_ids(), 30)
    links = Link.by_ids(ids)
    return rss_page(feed, links)
Exemplo n.º 4
0
def new():
    links = new_links(current_app.config["DEFAULT_FEEDS"])
    paginated_ids, has_less, has_more = paginate(links, 20)
    links = Link.by_ids(paginated_ids)

    return render_template(
        "index.html",
        links=links,
        less_links=has_less,
        more_links=has_more,
        title="eSource News - New",
    )
Exemplo n.º 5
0
def best():
    time = request.args.get("time")
    links = best_links(current_app.config["DEFAULT_FEEDS"],
                       time_limit=time if time else "all")
    paginated_ids, has_less, has_more = paginate(links, 20)
    links = Link.by_ids(paginated_ids)

    return render_template(
        "index.html",
        links=links,
        less_links=has_less,
        more_links=has_more,
        title="eSource News - Best",
    )
Exemplo n.º 6
0
def index_rss():
    if current_user.is_authenticated:
        links = trending_links(current_user.subscribed_feed_ids)
    else:
        links = trending_links(current_app.config["DEFAULT_FEEDS"])
    paginated_ids, _, _ = paginate(links, 30)
    links = Link.by_ids(paginated_ids)

    # TODO maybe do through fake feed (that's what reddit does and it actually makes sense)
    fg = FeedGenerator()
    fg.id("https://localhost:5000/")
    fg.title("Newsfeed")
    fg.link(href="http://localhost:5000/", rel="self")
    fg.description("Global news agrregator!")
    fg.language("en")

    for entry in rss_entries(links):
        fg.add_entry(entry)

    return fg.rss_str(pretty=True)