Ejemplo n.º 1
0
def bookmark_lookup():
    """ Look up a feed based on this URL """

    if 'user_id' not in session:
        abort(401)

    if not request.values.has_key('url') or not request.values['url']:
        print "rendered"
        return render_template('bookmark/add.html')

    url = request.values['url']
    url_bits = urlparse.urlparse(url)
    url_host = url_bits[1].lstrip("www.")

    flask_base = url_for("home", _external=True)
    flask_base_bits = urlparse.urlparse(flask_base)
    flask_base_host = flask_base_bits[1].lstrip("www.")

    if (url_host == flask_base_host):
        return render_template('bookmark/add.html',
                               error="Sorry, I can't add myself as a feed.")

    url = psutil.url_sanify(url)

    feed = psutil.feed_detect(url)

    if not feed:
        return render_template(
            'bookmark/add.html',
            error=
            "Sorry, I couldn't find an RSS feed for the URL <a href='%s'>%s</a>. Please verify that one exists. If you can find an RSS feed manually, try entering the feed URL directly."
            % (url, url))

    stamp = psutil.feed_modified(feed)
    app.logger.warning("stamp %s", stamp)
    if url == feed:
        url = stamp['link']

    bookmark = {'url': url, 'rss': feed, 'title': stamp['title'], 'tags': []}

    return render_template('bookmark/save.html', bookmark=bookmark)
Ejemplo n.º 2
0
def main():
    if len(sys.argv) > 1 and sys.argv[1] == "-q":
        sys.stdout = open('/dev/null', 'w')

    try:
        db = pysoso.connect_db()
        db.row_factory = sqlite3.Row
        rv = db.execute('select * from feed').fetchall()
        entries = [ dict(entry) for entry in rv ]
        db.close()

        for entry in entries:
            print "%s" % entry['rss']
            stamp = psutil.feed_modified(entry['rss'], entry['modified'], entry['etag'])
            if stamp:
                print " - feed modified since last access"
                entry['stamp'] = stamp
            else:
                print " - feed not modified"

        db = pysoso.connect_db()
        db.row_factory = sqlite3.Row
        c = db.cursor()

        for entry in entries:
            if 'stamp' in entry:
                stamp = entry['stamp']
                print " - updating: %s" % entry['rss']
                c.execute('update feed set modified = ?, etag = ? where feed_id = ?', (stamp['modified'], stamp['etag'], entry['feed_id']))
                if stamp['modified'] > entry['modified']:
                    print "   - got new entries"
                    c.execute('update bookmark set stale = 0 where feed_id = ?', (entry['feed_id'],))

        db.commit()
        db.close()

    except sqlite3.Error, e:
        sys.stderr.write("An error occurred: %s\n" % e.args[0])