本文整理汇总了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)
示例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))
示例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)
示例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))
示例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)
示例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)
示例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)
示例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)
示例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)
示例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})
示例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
示例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)
示例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())
示例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)
示例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)