当前位置: 首页>>代码示例>>Python>>正文


Python Feed.get方法代码示例

本文整理汇总了Python中models.Feed.get方法的典型用法代码示例。如果您正苦于以下问题:Python Feed.get方法的具体用法?Python Feed.get怎么用?Python Feed.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Feed的用法示例。


在下文中一共展示了Feed.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: feed_update

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get [as 别名]
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)
开发者ID:KyubiSystems,项目名称:Wisewolf,代码行数:37,代码来源:views.py

示例2: feed

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get [as 别名]
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)])
开发者ID:KyubiSystems,项目名称:Wisewolf,代码行数:31,代码来源:views.py

示例3: getFavicon

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get [as 别名]
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
开发者ID:KyubiSystems,项目名称:Wisewolf,代码行数:34,代码来源:Imgcache.py

示例4: add_feed

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get [as 别名]
 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
开发者ID:matsufan,项目名称:bottle-fever,代码行数:11,代码来源:feeds.py

示例5: fetch_feeds

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get [as 别名]
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
开发者ID:saga,项目名称:kindledump,代码行数:50,代码来源:tasks.py


注:本文中的models.Feed.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。