Exemple #1
0
def addurl(ids=''):
    db = RSS_Resource_db()
    if ids:
        rids = map(parse_rid, ids.split(','))
    else:
        rids = []

    url = request.form['url']
    if not url:
        raise NotFound()

    while url != None:
        resource = RSS_Resource(url, db, generate_id)
        url, seq = resource.redirect_info(db)

    if resource.id() not in rids:
        rids.append(resource.id())

    ridlist = map(format_rid, rids)
    raise RequestRedirect(url_for('page', ids=','.join(ridlist)))
Exemple #2
0
def addurl(ids=''):
    db = RSS_Resource_db()
    if ids:
        rids = map(parse_rid, ids.split(','))
    else:
        rids = []

    url = request.form['url']
    if not url:
        raise NotFound()

    while url != None:
        resource = RSS_Resource(url, db, generate_id)
        url, seq = resource.redirect_info(db)

    if resource.id() not in rids:
        rids.append(resource.id())

    ridlist = map(format_rid, rids)
    raise RequestRedirect(url_for('page', ids=','.join(ridlist)))
Exemple #3
0
def opml(ids=''):
    db = RSS_Resource_db()
    if ids:
        rids = map(parse_rid, ids.split(','))
    else:
        rids = []
    items = []

    for rid in rids:
        try:
            url = RSS_Resource_id2url(rid, db.cursor())
            while url != None:
                resource = RSS_Resource(url, db, generate_id=generate_id)
                url, seq = resource.redirect_info(db)

            items.append(resource)
        except KeyError:
            pass

    response = current_app.response_class(render_template('subscriptions.xml', items=items), mimetype='application/xml')
    return response
Exemple #4
0
def opml(ids=''):
    db = RSS_Resource_db()
    if ids:
        rids = map(parse_rid, ids.split(','))
    else:
        rids = []
    items = []

    for rid in rids:
        try:
            url = RSS_Resource_id2url(rid, db.cursor())
            while url != None:
                resource = RSS_Resource(url, db, generate_id=generate_id)
                url, seq = resource.redirect_info(db)

            items.append(resource)
        except KeyError:
            pass

    response = current_app.response_class(render_template('subscriptions.xml', items=items), mimetype='application/xml')
    return response
Exemple #5
0
def feed(url, db=None, templ=app.jinja_env.get_template('feed.html')):
    now = int(time.time())
    if db == None:
        db = RSS_Resource_db()

    while url != None:
        resource = RSS_Resource(url, db, generate_id=generate_id)
        url, seq = resource.redirect_info(db)

    next_update = resource.next_update(False)

    if next_update <= now:
        new_items, next_item_id, redirect_resource, redirect_seq, redirects = resource.update()

        if redirect_resource != None:
            resource = redirect_resource

    channel_info = resource.channel_info()
    channel_title = channel_info.title
    if not channel_title.strip():
        channel_title = channel_info.link
    if not channel_title.strip():
        channel_title = resource.url()

    last_updated, last_modified, invalid_since = resource.times()
    last_updated = time.asctime(time.gmtime(last_updated))
    if last_modified:
        last_modified = time.asctime(time.gmtime(last_modified))

    if invalid_since:
        error_info = resource.error_info()
    else:
        error_info = ''

    items, last_id = resource.get_headlines(None)
    items = items[-15:]
    items.reverse()

    for item in items:
        item.published = format_timestamp(item.published)

    return (resource.id(), templ.render(rid=format_rid(resource.id()),
                                        url=resource.url(),
                                        link=channel_info.link,
                                        title=channel_title,
                                        penalty=100*resource.penalty() / 1024,
                                        updated=last_modified,
                                        polled=last_updated,
                                        error_info=error_info,
                                        items=items))
Exemple #6
0
init_parserss()
db = RSS_Resource_db()
now = int(time.time())
rewriter = UrlRewriter(rewrite_db)

epub = ZipFile(epubname, 'w', ZIP_DEFLATED)
epub.writestr('mimetype', 'application/epub+zip', ZIP_STORED)
epub.writestr('META-INF/container.xml', CONTAINER_XML)

sess = get_http_session()
rss_titles, pageinfo, visited, resources = [], [], {}, {}

for rss in args:
    while rss != None:
        resource = RSS_Resource(rss, db)
        rss, seqnr = resource.redirect_info(db)

    resource.update(db)
    channel_info = resource.channel_info()
    items, nextid = resource.get_headlines(None, None, db)

    rss_titles.append(channel_info.title)

    for item in items:
        if item.published and item.published < now - age * 60 * 60:
            continue

        url = rewriter.rewrite(item.link)

        if visited.get(url):
Exemple #7
0
def feed(url, rewriter, db=None, templ=app.jinja_env.get_template('feed.html')):
    now = int(time.time())
    if db == None:
        db = RSS_Resource_db()

    while url != None:
        resource = RSS_Resource(url, db, generate_id=generate_id)
        url, seq = resource.redirect_info(db)

    next_update = resource.next_update(False)

    if next_update <= now:
        new_items, next_item_id, redirect_resource, redirect_seq, redirects = resource.update()

        if redirect_resource != None:
            resource = redirect_resource

    channel_info = resource.channel_info()
    channel_title = channel_info.title
    if not channel_title.strip():
        channel_title = channel_info.link
    if not channel_title.strip():
        channel_title = resource.url()

    last_updated, last_modified, invalid_since = resource.times()
    last_updated = time.asctime(time.gmtime(last_updated))
    if last_modified:
        last_modified = time.asctime(time.gmtime(last_modified))

    if invalid_since:
        error_info = resource.error_info()
    else:
        error_info = ''

    items, last_id = resource.get_headlines(None)
    items = items[-15:]
    items.reverse()

    for item in items:
        item.published = format_timestamp(item.published)
        item.link = rewriter.rewrite(item.link)

    return (resource.id(), templ.render(rid=format_rid(resource.id()),
                                        url=resource.url(),
                                        link=channel_info.link,
                                        title=channel_title,
                                        penalty=100*resource.penalty() / 1024,
                                        updated=last_modified,
                                        polled=last_updated,
                                        error_info=error_info,
                                        items=items))