Python bottle.post() Examples

The following are 8 code examples of bottle.post(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module bottle , or try the search function .
Example #1
Source File: runner.py    From puppet with MIT License 6 votes vote down vote up
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) 
Example #2
Source File: svrmain.py    From wechat_bot with GNU General Public License v2.0 6 votes vote down vote up
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 
Example #3
Source File: webIndex.py    From AcrosticPoem with MIT License 6 votes vote down vote up
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>
    ''' 
Example #4
Source File: server.py    From homu with MIT License 5 votes vote down vote up
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') 
Example #5
Source File: svrmain.py    From wechat_bot with GNU General Public License v2.0 5 votes vote down vote up
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'] 
Example #6
Source File: svrmain.py    From wechat_bot with GNU General Public License v2.0 5 votes vote down vote up
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'执行操作失败!'} 
Example #7
Source File: server.py    From cloudify-plugins-common with Apache License 2.0 4 votes vote down vote up
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 
Example #8
Source File: svrmain.py    From wechat_bot with GNU General Public License v2.0 4 votes vote down vote up
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'无输入值'}