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


Python Feed.query方法代码示例

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


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

示例1: create_feed

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import query [as 别名]
def create_feed(user,board_id,title,link,description,actions,public_board,get_all,token):
    """ Creates a feed and attaches it to a user object """
    user = get_user(user)
    q = Feed.query(
        Feed.channel_title==title,
        Feed.channel_link==link,
        Feed.channel_description==description,
        Feed.feed_name==title,
        Feed.token==token,
        Feed.actions.IN(actions),
        Feed.board_id==board_id,
        Feed.public_board==public_board)
    feed = q.get()
    if feed is None:
        feed = Feed(
            channel_title=title,
            channel_link=link,
            channel_description=description,
            feed_name=title,
            token=token,
            actions=actions,
            board_id=board_id,
            public_board=public_board,
            get_all=get_all,user=user.key)
        feed.put()
    if user.feeds:
        if feed.key not in user.feeds:
            user.feeds.append(feed.key)
            user.put()
    else:
        user.feeds = [feed.key]
        user.put()
    return create_url(feed.key.id())
开发者ID:naiyt,项目名称:trellorss-gae,代码行数:35,代码来源:utils.py

示例2: all_feeds

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import query [as 别名]
def all_feeds():
    """Post all new items for feeds for a specific interval"""

    def feed_to_dict(feed):
        return {
            'feed_key': feed.key.urlsafe(),
            'feed_url': feed.feed_url,
            'etag': feed.etag,
            'last_hash': feed.last_fetched_content_hash,
        }

    qit = Feed.query().iter()
    feeds_response = []
    while (yield qit.has_next_async()):
        feeds_response.append(feed_to_dict(qit.next()))

    poller_run_id = uuid.uuid4().hex

    logger.info('Poller run %s dispatched with %d feeds', poller_run_id, len(feeds_response))

    response = {
        'poller_run_id': poller_run_id,
        'feeds': feeds_response,
    }

    raise ndb.Return(jsonify(status='ok', data=response))
开发者ID:ianmintz,项目名称:pourover,代码行数:28,代码来源:views.py

示例3: try_push_resub

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import query [as 别名]
def try_push_resub():
    """Post all new items for feeds for a specific interval"""
    if request.headers.get('X-Appengine-Cron') != 'true':
        raise ndb.Return(jsonify_error(message='Not a cron call'))

    unsubscribed_feeds = Feed.query(Feed.hub != None, Feed.subscribed_at_hub == False)  # noqa
    qit = unsubscribed_feeds.iter()

    errors = 0
    success = 0
    count = 0

    futures = []

    while (yield qit.has_next_async()):
        feed = qit.next()
        futures.append((feed, Feed.subscribe_to_hub(feed)))

    for feed, future in futures:
        count += 1
        try:
            yield future
            success += 1
        except:
            errors += 1
            logger.exception('Failed to PuSH subscribe feed:%s' % (feed.feed_url, ))

    logger.info('Tried to call hub for num_unsubscribed_feeds:%s success:%s, errors:%s', count, success, errors)

    raise ndb.Return(jsonify(status='ok'))
开发者ID:ianmintz,项目名称:pourover,代码行数:32,代码来源:views.py

示例4: post_all_feeds

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import query [as 别名]
def post_all_feeds():
    """Post all new items for feeds for a specific interval"""
    if request.headers.get('X-Appengine-Cron') != 'true':
        raise ndb.Return(jsonify_error(message='Not a cron call'))

    feeds = Feed.query().iter()

    errors = 0
    success = 0
    num_posted = 0
    futures = []

    while (yield feeds.has_next_async()):
        feed = feeds.next()
        futures.append((feed, Entry.publish_for_feed(feed)))

    for feed, future in futures:
        try:
            num_posts = yield future
            if num_posts is not None:
                num_posted += num_posts
            success += 1
        except:
            errors += 1
            logger.exception('Failed to Publish feed:%s' % (feed.feed_url, ))

    logger.info('Post Feeds success:%s errors: %s num_posted: %s', success, errors, num_posted)

    raise ndb.Return(jsonify(status='ok'))
开发者ID:berg,项目名称:pourover,代码行数:31,代码来源:views.py

示例5: rpc_fetch

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import query [as 别名]
    def rpc_fetch():
        q = Feed.query()
        results = ndb.get_multi(q.fetch(keys_only=True))

        rpcs = []
        for f in results:
            rpc = urlfetch.create_rpc()
            urlfetch.make_fetch_call(rpc, f.url)
            rpcs.append(rpc)

        for rpc in rpcs:
            rpc.wait()
            result = rpc.get_result()
            d = feedparser.parse(result.content)
            for e in d['entries']:
                dt = parser.parse(e["published"]).replace(tzinfo=None)
                dy = (datetime.datetime.utcnow() - datetime.timedelta(days=COLLECT_DAYS, seconds=COLLECT_HOURS*3600)).replace(tzinfo=None)
                if dt > dy:
                    obj = EntryCollect.get_or_insert(e["id"])
                    if obj.published and obj.published >= dt:
                        pass
                    else:
                        logging.info("new entry : %s" % e["id"])
                        obj.published = dt
                        obj.title = e["title"]
                        obj.link = e["link"]
                        obj.summary = clean_html(e["summary"])
                        obj.feed = d['feed']['title']
                        obj.need_collect_word = True
                        obj.need_notice = True
                        obj.put()
开发者ID:lichenxi,项目名称:StockNewsGAE,代码行数:33,代码来源:controller.py

示例6: getFeedsCreated

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import query [as 别名]
    def getFeedsCreated(self, request):
        """Return feeds created by user."""
        # make sure user is authed
        user = endpoints.get_current_user()
        if not user:
            raise endpoints.UnauthorizedException('Authorization required')

        # make profile key
        p_key = ndb.Key(Profile, getUserId(user))
        # create ancestor query for this user
        feeds = Feed.query(ancestor=p_key)
        return FeedForms(items=[self._copyFeedToForm(feed) for feed in feeds])
开发者ID:nickyfoto,项目名称:Endpoints,代码行数:14,代码来源:reader.py

示例7: post

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import query [as 别名]
    def post(self):
        """Create a new feed and save it to the database"""
        feed_url = self.request.get('feed_url')

        logging.info("URL POSTed: %s" % feed_url)

        if feed_url:
            # Check if we already have this feed
            qry = Feed.query(Feed.url == feed_url)
            if qry.count() == 0:
                # Retrieve the feed details and then save it to the Datastore
                try:
                    feed = create_feed_from_url(feed_url)

                    # Do another check to see if we're following this feed
                    # The URL may have redirected
                    qry = Feed.query(Feed.url == feed.url)
                    if qry.count() > 0:
                        return webapp2.Response(status=409,
                            body="You're already following that feed")

                    # Set the date of last post to now so we only look for future posts
                    feed.last_checked = datetime.min

                    feed.put()

                    self.response.headers['Content-Type'] = 'application/json'
                    obj = {
                        'feed_name': feed.name,
                        'feed_url': feed.url
                    }
                    self.response.out.write(json.dumps(obj))
                except Exception as e:
                    return webapp2.Response(status=400, body=e.message)
            else:
                return webapp2.Response(status=409, body="You're already following that feed")
        else:
            return webapp2.Response(status=400, body="Missing parameter 'feed_url'")
开发者ID:adrian,项目名称:feed2me,代码行数:40,代码来源:views.py

示例8: get

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import query [as 别名]
    def get(self):
        feeds_query = Feed.query(ancestor=root_key())
        feeds = feeds_query.fetch()

        template_values = {
            'feeds': feeds,
        }

        # A logout URL is useful during dev
        DEV = os.environ['SERVER_SOFTWARE'].startswith('Development')
        if DEV:
            template_values['logout_url'] = users.create_logout_url('/')

        template = JINJA_ENVIRONMENT.get_template('templates/feeds.html')
        self.response.write(template.render(template_values))
开发者ID:adrian,项目名称:feed2me,代码行数:17,代码来源:views.py

示例9: delete

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import query [as 别名]
    def delete(self):
        """Delete a feed from the database"""
        feed_url = self.request.get('feed_url')

        logging.info("URL DELETEed: %s" % feed_url)

        if feed_url:
            unquoted_url = urllib.unquote(feed_url)
            unescaped_url = HTMLParser.HTMLParser().unescape(unquoted_url)
            qry = Feed.query(Feed.url == unescaped_url)
            if qry.count():
                feed = qry.get()
                feed.key.delete()
            else:
                return webapp2.Response(status=404, body="Feed doesn't exist")
        else:
            return webapp2.Response(status=400, body="Missing parameter 'feed_url'")
开发者ID:adrian,项目名称:feed2me,代码行数:19,代码来源:views.py

示例10: all_feeds

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import query [as 别名]
def all_feeds():
    """Post all new items for feeds for a specific interval"""
    access_token = request.headers.get('Authorization', '').replace('Bearer ', '')

    ctx = ndb.get_context()
    resp = yield ctx.urlfetch('https://alpha-api.app.net/stream/0/token', headers={'Authorization': 'Bearer %s' % (access_token)})
    if resp.status_code != 200:
        logger.info('Token call failed: %s' % resp.content)
        raise ndb.Return(jsonify_error('Not Authorized', code=401))

    token = json.loads(resp.content).get('data', {})

    if token.get('app', {}).get('client_id') != app.config['CLIENT_ID']:
        logger.info('Client ID mismatch: %s' % resp.content)
        raise ndb.Return(jsonify_error('Not Authorized', code=401))

    if token.get('user'):
        logger.info('Token had a user not an app token: %s' % resp.content)
        raise ndb.Return(jsonify_error('Not Authorized', code=401))

    feeds = Feed.query().iter()

    feeds_response = []

    def feed_to_dict(feed):
        return {
            'feed_key': feed.key.urlsafe(),
            'feed_url': feed.feed_url,
            'etag': feed.etag,
            'last_hash': feed.last_fetched_content_hash,
        }

    while (yield feeds.has_next_async()):
        feed = feeds.next()
        feeds_response.append(feed_to_dict(feed))

    logger.info('Returning all the feeds')
    raise ndb.Return(jsonify(status='ok', data=feeds_response))
开发者ID:berg,项目名称:pourover,代码行数:40,代码来源:views.py

示例11: get_feeds

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import query [as 别名]
def get_feeds():
    feeds = Feed.query().order(Feed.title)
    entries = Entry.query().order(-Entry.published)

    return feeds, entries
开发者ID:barykaed,项目名称:comic-scraper,代码行数:7,代码来源:main.py

示例12: get

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import query [as 别名]
    def get(self):
        an_hour_ago = dt.datetime.now() - dt.timedelta(hours=1)
        feeds = Feed.query(Feed.checked < an_hour_ago)

        for feed in feeds:
            self.update(feed.link)
开发者ID:barykaed,项目名称:comic-scraper,代码行数:8,代码来源:main.py

示例13: queryFeeds

# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import query [as 别名]
 def queryFeeds(self, request):
     """ query all feeds added by all users"""
     feeds = Feed.query()
     return FeedForms(
         items=[self._copyFeedToForm(feed) for feed in feeds])
开发者ID:nickyfoto,项目名称:Endpoints,代码行数:7,代码来源:reader.py


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