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


Python RequestHelper.write_json方法代码示例

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


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

示例1: post

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import write_json [as 别名]
    def post(self, **kw):
        helper = RequestHelper(self)
        results = {}
        source_q = ArtifactSource.all()
        for s in source_q:
            artifact_q = ArtifactInfo.find_by_source(s)
            count = len([a for a in artifact_q])
            counter = Counters.source_counter(s.name)
            old_count = counter.count()
            counter.set(count)
            
            source_result = { 'old': old_count }
            
            # if source is linked to a feed, I can't delete it
            feed = Feed.get_by_source(s, return_none=True)
            if feed:
                source_result['feed'] = feed.url

            if not count and not feed:
                s.delete()
                source_result['deleted'] = True
            
            if count:
                source_result['new'] = count
                
            results[s.name] = source_result
        helper.write_json(results)
开发者ID:mhawthorne,项目名称:antonym,代码行数:29,代码来源:sources.py

示例2: get

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import write_json [as 别名]
 def get(self, name, **kw):
     helper = RequestHelper(self)
     source = ArtifactSourceAccessor.get_by_name(name, return_none=True)
     if not source:
         helper.error(404)
         return
     helper.write_json(source_hash(source))
开发者ID:mhawthorne,项目名称:antonym,代码行数:9,代码来源:sources.py

示例3: get

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import write_json [as 别名]
    def get(self, **kw):
        helper = RequestHelper(self)
        q = self.request.get("q", None)
        output = self.request.get("o", None)
        max_results = int(self.request.get("max", -1))
        
        if not q:
            helper.error(400, "q not provided.")
            return

        q_results = ArtifactContent.all().search(q)

        json_results = None
        if output == "short":
            json_results = {}
            json_results["count"] = q_results.count()
        elif output == "id":
            json_results = {}
            count = q_results.count()
            if max_results > 0 and max_results < q_results.count():
                count = max_results
                
            json_results["count"] = count
            ids = []
            json_results["ids"] = ids
            results = q_results.fetch(1000) if max_results == -1 else q_results.fetch(max_results)
            for c in results:
                ids.append(c.guid)
        else:
            json_results = []
            if q_results.count():
                for content in q_results.fetch(10):
                    info = ArtifactInfo.get_by_guid(content.guid)
                    json_results.append(ArtifactsHelper.artifact_to_hash(info, content))
        helper.write_json(json_results)
开发者ID:mhawthorne,项目名称:antonym,代码行数:37,代码来源:artifacts.py

示例4: get

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import write_json [as 别名]
 def get(self, source_name):
     helper = RequestHelper(self)
     source_name = urllib.unquote(source_name)
     f = Feed.get_by_source_name(source_name, return_none=True)
     if not f:
         helper.error(404)
         return
     helper.write_json(build_feed_hash(f))
开发者ID:mhawthorne,项目名称:antonym,代码行数:10,代码来源:feeds.py

示例5: get

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import write_json [as 别名]
 def get(self):
     helper = RequestHelper(self)
     results = []
     for s in db.stats.KindStat.all():
         results.append({'kind': s.kind_name,
             'count': s.count,
             'bytes': s.bytes})
     helper.write_json(results)
开发者ID:mhawthorne,项目名称:antonym,代码行数:10,代码来源:da.py

示例6: get

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import write_json [as 别名]
 def get(self, page):
     page = int(page) if page else 0
     
     helper = RequestHelper(self)
     results = []
     for u in UrlResource.all().fetch(self.BATCH_SIZE, page * self.BATCH_SIZE):
         results.append(resource_hash(u))
     helper.write_json(results)
开发者ID:mhawthorne,项目名称:antonym,代码行数:10,代码来源:resources.py

示例7: get

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import write_json [as 别名]
    def get(self, **kw):
        helper = RequestHelper(self)

        # read actions from queue; return as json
        q = get_activity_queue()
        items = q.items()

        helper.write_json(items)
开发者ID:mhawthorne,项目名称:antonym,代码行数:10,代码来源:activity.py

示例8: delete

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import write_json [as 别名]
 def delete(self):
     helper = RequestHelper(self)
     search_results = self.__search(helper)
     if search_results:
         keys = [u.key() for u in search_results]
         db.delete(keys)
         helper.write_json([k.name() for k in keys])
     else:
         helper.set_status(204)
开发者ID:mhawthorne,项目名称:antonym,代码行数:11,代码来源:resources.py

示例9: get

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import write_json [as 别名]
 def get(self, path):
     helper = RequestHelper(self)
     t_api = TwitterConnector.new_api()
     try:
         result_hash = t_api.FetchResource("%s" % path)
         logging.debug("result_hash: %s" % result_hash)
         helper.write_json(result_hash)
     except twitter.TwitterError, e:
         helper.write(e)
开发者ID:mhawthorne,项目名称:antonym,代码行数:11,代码来源:tweeter.py

示例10: get

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import write_json [as 别名]
 def get(self):
     helper = RequestHelper(self)
     
     # calculates random number of minutes
     minute = random.choice(self._minutes)
     
     taskqueue.add(url=SafeTwitterActorHandler.PATH, countdown=minute * 60)
     msg = 'scheduled %d minutes in the future' % minute
     logging.debug(msg)
     helper.write_json({'msg': msg})
开发者ID:mhawthorne,项目名称:antonym,代码行数:12,代码来源:cron.py

示例11: __default

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import write_json [as 别名]
 def __default(self):
     helper = RequestHelper(self)
     m = self.request.method
     if m in ("DELETE", "PUT"):
         sleep = random.randint(0, 10) / 2
         logging.debug("sleeping for %ds" % sleep)
         time.sleep(sleep)
     elif m == "GET":
         helper.write_json({'msg': 'hack success'})
     else:
         pass
开发者ID:mhawthorne,项目名称:antonym,代码行数:13,代码来源:debug.py

示例12: respond

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import write_json [as 别名]
 def respond(cls, handler):
     helper = RequestHelper(handler)
     directs, publics = TwitterActor().respond()
     
     if not directs:
         directs = 0
     if not publics:
         publics = 0
         
     result = dict(directs=directs, publics=publics)
     helper.write_json(result)        
开发者ID:mhawthorne,项目名称:antonym,代码行数:13,代码来源:tweeter.py

示例13: post

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import write_json [as 别名]
 def post(self):
     helper = RequestHelper(self)
     
     if not len(self.request.body):
         helper.error(400, "body required")
         return
         
     decoded_body = urllib.unquote(self.request.body)
     t_api = TwitterConnector.new_api()
     status = t_api.PostUpdate(decoded_body)
     helper.write_json(status.asDict())
开发者ID:mhawthorne,项目名称:antonym,代码行数:13,代码来源:tweeter.py

示例14: get

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import write_json [as 别名]
 def get(self, **kw):
     helper = RequestHelper(self)
     message = self.request.get("q", None)
     if not message:
         helper.error(400, "q must be provided")
         return
     message = urllib.unquote(message)
     try:
         sources, response = Mixer(new_speaker()).mix_response(message)
         logging.debug("sources:%s, response:%s" % (sources, response))
         result = dict(response=response)
         helper.write_json(result)
     except DataException, ex:
         helper.error(503, Exceptions.format(ex))
         logging.error(ex)
开发者ID:mhawthorne,项目名称:antonym,代码行数:17,代码来源:mixtures.py

示例15: get

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import write_json [as 别名]
 def get(self, key):
     helper = RequestHelper(self)
     config = ConfigurationAccessor.get_or_create()
     result = None
     if config:
         if key:
             if entity_has_property(config, key):
                 result = getattr(config, key)
             else:
                 helper.error(400, "invalid key")
                 return
         else:
             result = entity_to_hash(config)
     else:
         result = {}
     helper.write_json(result)
开发者ID:mhawthorne,项目名称:antonym,代码行数:18,代码来源:config.py


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