コード例 #1
0
ファイル: views.py プロジェクト: KyubiSystems/Wisewolf
def feed_update(id=None):

    # Manual update of one or all feeds now
    if request.json['action'] == 'refresh':
        
        # Call refresh routine
        # TODO: RSS worker functions in separate package
        # TODO: Need to capture return status
        if id is None:
            rss_spawn() # Update all feeds
        else:
            try:
                feed = Feed.get(Feed.id == id)
            except Feed.DoesNotExist:
                return jsonify(**FEED_NOT_FOUND)

            rss_worker(feed) # Update single feed
        
        # return JSON status OK
        return jsonify(**STATUS_OK)

    # Mark one or all feeds read
    elif request.json['action'] == 'markread':

        if id is None:
            # Mark all posts read
            query = Post.update(is_read=True)
        else:
            # Mark posts in current feed read
            query = Post.update(is_read=True).where(Feed.id == id)
            
        query.execute()
            
    # return JSON status OK
        return jsonify(**STATUS_OK)
コード例 #2
0
ファイル: views.py プロジェクト: KyubiSystems/Wisewolf
def feed(id=None):
    # Get feed number <id>
    try:
        feed = Feed.get(Feed.id == id)
    except Feed.DoesNotExist:
        return jsonify(**FEED_NOT_FOUND)

    # populate Category tree
    (categories, feeds) = loadTree()

    # Get posts in decreasing date order
    posts = Post.select().join(Feed).where(Feed.id == id).order_by(Post.published.desc()).paginate(1, 50)

    # Create human-readable datestamps for posts
    datestamps = loadDates(posts)

    # Select return format on requested content-type?
    if request.json is None:
        # Render feed page template
        return render_template("feed.html", 
                               categories=categories, 
                               feeds=feeds, 
                               feed=feed, 
                               posts=posts,
                               datestamps=datestamps)

    else:
        # Return JSON here for client-side formatting?
        return jsonify(response=[dict(feed=feed, posts=posts)])
コード例 #3
0
ファイル: Imgcache.py プロジェクト: KyubiSystems/Wisewolf
def getFavicon(feed_id):

    # Favicon HTTP content types
    favicon_types = ["image/vnd.microsoft.icon", "image/x-icon"]

    feed = Feed.get(Feed.id == feed_id)
    url = feed.url
    u = urlparse(url)
    favicon_url = 'http://' + u.netloc + '/favicon.ico'
    log.info("getFavicon: Looking for favicon at %s", favicon_url)
    try:
        r = requests.get(favicon_url, stream=True, timeout=5)
        content_type = r.headers.get('content-type')
        if r.status_code == requests.codes.ok and content_type in favicon_types: # pylint: disable=maybe-no-member
            log.info("getFavicon: returned from urllib, content-type %s", content_type)
        else:
            return None

    except Exception:
        return None

    log.info("Favicon %s status: %s", str(feed_id), str(r.status_code))

    favicon_path = '{0}favicon_{1}.ico'.format(ICONS_PATH, str(feed_id))  # Full file path to favicon
    favicon_file = 'favicon_{0}.ico'.format(str(feed_id)) # favicon filename

    with open(favicon_path, 'wb') as fav:
        shutil.copyfileobj(r.raw, fav)
    del r

    # Return filename of favicon
    return favicon_file
コード例 #4
0
ファイル: views.py プロジェクト: KyubiSystems/Wisewolf
def feed_update(id=None):

    # Manual update of one or all feeds now
    if request.json['action'] == 'refresh':

        # Call refresh routine
        # TODO: RSS worker functions in separate package
        # TODO: Need to capture return status
        if id is None:
            rss_spawn() # Update all feeds
        else:
            try:
                feed = Feed.get(Feed.id == id)
            except Feed.DoesNotExist:
                return jsonify(**FEED_NOT_FOUND)

            rss_worker(feed) # Update single feed

        # return JSON status OK
        return jsonify(**STATUS_OK)

    # Mark one or all feeds read
    elif request.json['action'] == 'markread':

        if id is None:
            # Mark all posts read
            query = Post.update(is_read=True)
        else:
            # Mark posts in current feed read
            query = Post.update(is_read=True).where(Feed.id == id)

        query.execute()

    # return JSON status OK
        return jsonify(**STATUS_OK)
コード例 #5
0
ファイル: views.py プロジェクト: KyubiSystems/Wisewolf
def feed(id=None):
    # Get feed number <id>
    try:
        feed = Feed.get(Feed.id == id)
    except Feed.DoesNotExist:
        return jsonify(**FEED_NOT_FOUND)

    # populate Category tree
    (categories, feeds) = loadTree()

    # Get posts in decreasing date order
    posts = Post.select().join(Feed).where(Feed.id == id).order_by(Post.published.desc()).paginate(1, 50)

    # Create human-readable datestamps for posts
    datestamps = loadDates(posts)

    # Select return format on requested content-type?
    if request.json is None:
        # Render feed page template
        return render_template("feed.html",
                               categories=categories,
                               feeds=feeds,
                               feed=feed,
                               posts=posts,
                               datestamps=datestamps)

    else:
        # Return JSON here for client-side formatting?
        return jsonify(response=[dict(feed=feed, posts=posts)])
def rss(feed):
    try:
        fd = Feed.get(Feed.id == feed, Feed.user == current_user.id)
        return render_template("rss.html",
                               feed=fd,
                               entries=feedparser.parse(fd.url).entries)
    except Feed.DoesNotExist:
        abort(404)
def delete_feed():
    feed = request.form['feed']
    try:
        fd = Feed.get(Feed.id == feed, Feed.user == current_user.id)
        fd.delete_instance()
        return jsonify(status='OK')
    except Feed.DoesNotExist:
        return jsonify(status='FAIL')
コード例 #8
0
def rss(feed):
    # Con el id del feed obtengo el feed para mostrarlo con rss.
    try:
        feed_new = Feed.get(Feed.id == feed)
    except:
        return redirect(url_for('index'))
    feed = feedparser.parse(feed_new.url)
    return render_template('rss.html', feed=feed_new, entries=feed.entries)
コード例 #9
0
ファイル: feeds.py プロジェクト: matsufan/bottle-fever
 def add_feed(self, url, site_url = None, title = None, group = None):
     """Add a feed to the database"""
     # existing feed?
     try:
         f = Feed.get(Feed.url == url)
     except Feed.DoesNotExist:
         f = Feed.create(url = url, title=title, site_url=site_url)
     db.close()
     return f
コード例 #10
0
ファイル: feeds.py プロジェクト: djdarkbeat/bottle-fever
 def add_feed(self, url, site_url=None, title=None, group=None):
     """Add a feed to the database"""
     # existing feed?
     try:
         f = Feed.get(Feed.url == url)
     except Feed.DoesNotExist:
         f = Feed.create(url=url, title=title, site_url=site_url)
     except:
         log.error(tb())
     return f
コード例 #11
0
def delete_feed(feed):
    # Verifico que el feed exista y elimino. Recordar que siempre los
    # id de los feeds no dan informacion del usuario. Por lo tanto
    # dos feeds iguales pero de distintos usuarios tienen distintos ids.
    try:
        feed_new = Feed.get(Feed.id == feed)
    except:
        return 'Error'
    feed_new.delete_instance()
    # Muestro el index.
    return redirect(url_for('index'))
コード例 #12
0
ファイル: tasks.py プロジェクト: saga/kindledump
def fetch_feeds(request):
    feed_key = request.POST.get('feed_key', None)

    if feed_key is None:
        logging.error('missing parameter')
        raise TypeError('missing parameter')

    feed = Feed.get(feed_key)
    if feed is None:
        logging.error('Feed object not found: %s', feed_key)
        raise TypeError('Feed object not found')

    parser = feedparser.parse(feed.url)

    # check if feed exists
    if hasattr(feed, 'bozo_exception'):
        feed.is_valid = False
        logging.warn('Invalid feed: %s;;%s', feed.id, feed.url)
        feed.put()
        return

    # setup feed title if does not exist
    if not feed.title:
        feed.title = parser.feed.title

    rd = ReadyData.gql("WHERE data_type = :1 AND owner = :2 LIMIT 1",
                'feed', feed.owner).get()
    if rd is None:
        rd = ReadyData(owner=feed.owner, data_type='feed')
        rd.content = ''

    for e in parser['entries']:
        # TODO - check the date

        article = '<h1>%(title)s</h1>' % e
        for content in e['content']:
            article += content['value']

        rd.content += article
        rd.merged += 1

    rd.put()
    feed.put()

    params = {'ready_data_key': rd.key()}
    taskqueue.add(url=reverse('fetcher-send'), params=params)

    return True