本文整理汇总了Python中bottle.post方法的典型用法代码示例。如果您正苦于以下问题:Python bottle.post方法的具体用法?Python bottle.post怎么用?Python bottle.post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bottle
的用法示例。
在下文中一共展示了bottle.post方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import post [as 别名]
def run(host='127.0.0.1', port=10086):
from bottle import post, run, request, response
@post('/puppet')
def serve():
'''Puppet Web Trading Interface'''
task = request.json
if task:
try:
return getattr(acc, task.pop('action'))(**task)
except Exception as e:
response.bind(status=502)
return {'puppet': str(e)}
return {'puppet': '仅支持json格式'}
print('Puppet version:', __version__)
acc = Account()
run(host=host, port=port)
示例2: fc_test
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import post [as 别名]
def fc_test():
q=request.forms.get('q')
if not q:
return
url="https://www.sogou.com/labs/webservice/sogou_word_seg.php"
r=requests.post(url,{'q':q.decode('utf8'),'fmt':'js'})
print q.decode('utf8')
print r.text
if not r.text:
return u'没有获取到数据'
j=json.loads(r.text)
r=''
if j['status']=='OK':
#print j['input']
for i in j['result']:
r+=i[0]+'|'+i[1]+' '
else:
print 'status error'
print j
return r
示例3: poem
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import post [as 别名]
def poem():
return '''
<h1>藏頭詩產生器</h1>
<hr>
<form action="/poem" method="post">
請輸入要藏的句子: <input name="input_str" type="text" value=""><br/>
每句字數:<select name="length">
<option value="5" selected="selected">五言</option>
<option value="7">七言</option>
</select><br/>
藏字位置<select name="position">
<option value="1" selected="selected">第一個字</option>
<option value="2">第二個字</option>
<option value="3">第三個字</option>
<option value="4">第四個字</option>
</select><br/>
回傳格式<select name="type">
<option value="html" selected="true">html</option>
<option value="json">json</option>
</select><br/>
<input value="Go" type="submit" />
</form>
'''
示例4: callback
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import post [as 别名]
def callback():
logger = g.logger.getChild('callback')
response.content_type = 'text/plain'
code = request.query.code
state = json.loads(request.query.state)
lazy_debug(logger, lambda: 'state: {}'.format(state))
res = requests.post('https://github.com/login/oauth/access_token', data={
'client_id': g.cfg['github']['app_client_id'],
'client_secret': g.cfg['github']['app_client_secret'],
'code': code,
})
args = urllib.parse.parse_qs(res.text)
token = args['access_token'][0]
repo_label = state['repo_label']
repo_cfg = g.repo_cfgs[repo_label]
repo = get_repo(repo_label, repo_cfg)
user_gh = github3.login(token=token)
if state['cmd'] == 'rollup':
return rollup(user_gh, state, repo_label, repo_cfg, repo)
elif state['cmd'] == 'synch':
return synch(user_gh, state, repo_label, repo_cfg, repo)
else:
abort(400, 'Invalid command')
示例5: do_turing
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import post [as 别名]
def do_turing():
#图灵机器人接口 可以自己注册key,目前作者的是5000条/天
#http://www.tuling123.com/openapi/record.do?channel=338
q=request.forms.get('q')
payload={'key':'9e01d5c29994c579040270b557a99295','info':q}
url="http://www.tuling123.com/openapi/api"
r=requests.post(url,params=payload)
return json.loads(r.text)['text']
示例6: do_admin
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import post [as 别名]
def do_admin():
#机器人后台调教
q=request.forms.get('q')
a=request.forms.get('a')
if q and a:
url="https://www.sogou.com/labs/webservice/sogou_word_seg.php"
r=requests.post(url,{'q':q.decode('utf8'),'fmt':'js'})
if not r.text:
return {'code':1,'msg':u'分词器1异常'}
qfc=json.loads(r.text)
r=requests.post(url,{'q':a.decode('utf8'),'fmt':'js'})
if not r.text:
return {'code':1,'msg':u'分词器2异常'}
afc=json.loads(r.text)
h={}
if qfc['status']=='OK':
for i in qfc['result']:
h[i[1]]=i[0]
db().set("INSERT IGNORE INTO `wb_ck` (`cy`, `cx`) VALUES (%s, %s)",(i[0],i[1]))
if afc['status']=='OK':
for i in afc['result']:
if h.has_key(i[1]):
db().set("INSERT IGNORE INTO `wb_ck` (`cy`, `cx`) VALUES (%s, %s)",(i[0],i[1]))
s1=db().get1("SELECT `id` FROM `wb_ck` WHERE `cy` = %s LIMIT 1",h[i[1]])[0]
s2=db().get1("SELECT `id` FROM `wb_ck` WHERE `cy` = %s LIMIT 1",i[0])[0]
db().set("INSERT IGNORE INTO `wb_gx` (`cid`, `kid`) VALUES (%s, %s)",(s1,s2))
db().set("UPDATE `wb_gx` SET `qz`=`qz`+1 WHERE (`cid`=%s)",s1)
return {'code':0}
return {'code':1,'msg':u'执行操作失败!'}
示例7: _start_server
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import post [as 别名]
def _start_server(self):
proxy = self
class BottleServerAdapter(bottle.ServerAdapter):
def run(self, app):
class Server(WSGIServer):
allow_reuse_address = True
def handle_error(self, request, client_address):
pass
class Handler(WSGIRequestHandler):
def address_string(self):
return self.client_address[0]
def log_request(*args, **kwargs):
if not self.quiet:
return WSGIRequestHandler.log_request(
*args, **kwargs)
self.srv = make_wsgi_server(
self.host,
self.port,
app,
Server,
Handler)
proxy.server = self.srv
self.port = self.srv.server_port
proxy._started.put(True)
self.srv.serve_forever(poll_interval=0.1)
bottle.post('/', callback=self._request_handler)
def serve():
bottle.run(
host='localhost',
port=self.port,
quiet=True,
server=BottleServerAdapter)
thread = threading.Thread(target=serve)
thread.daemon = True
thread.start()
return thread
示例8: do_mybot
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import post [as 别名]
def do_mybot():
#这里添加自己的机器人处理
q=request.forms.get('q')
if q:
url="https://www.sogou.com/labs/webservice/sogou_word_seg.php"
r=requests.post(url,{'q':q.decode('utf8'),'fmt':'js'})
if not r.text:
return {'code':1,'msg':u'分词器异常'}
qfc=json.loads(r.text)
h={}
if qfc['status']=='OK':
for i in qfc['result']:
r=db().get1(
"""SELECT
t2.cy,
t2.cx,
t1.qz
FROM
wb_ck AS t3
CROSS JOIN wb_gx AS t1 ON t3.id = t1.cid
OR t1.kid = t3.id
CROSS JOIN wb_ck AS t2 ON t1.cid = t2.id
OR t2.id = t1.kid
WHERE
t3.cy = %s
ORDER BY
t1.qz DESC""",i[0])
if r:
h[r[1]]=r[0]
if not h:
#return {'code':1,'msg':u'数据获取异常'}
return u'呃,不知道你在说什么'
g='rdvn'
s=''
for gg in g:
if h.has_key(gg):
s+=h[gg]
else:
if gg in 'rdvn':
r=db().get1(
"""SELECT
wb_ck.cy,
RAND() AS r
FROM
wb_ck
WHERE
wb_ck.cx = %s
ORDER BY
r
LIMIT 1""",gg)
s+=r[0]
return s
else:
return {'code':1,'msg':u'分词接口无有效数据'}
return {'code':1,'msg':u'无输入值'}