本文整理汇总了Python中bottle.get方法的典型用法代码示例。如果您正苦于以下问题:Python bottle.get方法的具体用法?Python bottle.get怎么用?Python bottle.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bottle
的用法示例。
在下文中一共展示了bottle.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getTotalSoftwares
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import get [as 别名]
def getTotalSoftwares():
response.set_header("Access-Control-Allow-Origin", "*")
db = mariadb.connect(user=Settings.MONITOR_DB['user'], password=Settings.MONITOR_DB['password'], database=Settings.MONITOR_DB['database'])
softwares = collections.OrderedDict()
maxDays = request.GET.get('maxDays', '31').strip()
maxDays = int(maxDays) - 1
query = """SELECT name, SUM(hits) AS total, MAX(dateStats) AS maxDate
FROM softwares
GROUP BY name
HAVING maxDate >= DATE_SUB(NOW(), INTERVAL %s DAY)
ORDER BY total DESC"""
results = db.cursor()
results.execute(query, (maxDays, ))
for row in results:
softwares[row[0].encode('utf8')] = str(row[1])
db.close()
return simplejson.dumps(softwares)
示例2: vpn_report
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import get [as 别名]
def vpn_report(name):
keyinfo= key_auth()
user = model.User.get(name)
if not 'dl' in request.forms:
abort(400, "Must include dl")
dl = int(request.forms['dl'])
if dl < 0:
abort(400, "dl must be >= 0")
user.dl_left = user.dl_left - dl
if user.dl_left < 0:
logger.email("dl_finished: " + ",".join(user.username, user.sub_end))
user.save()
log("Report for a user recieved (user disconnected from {0})".format(keyinfo.name))
return {}
#----------
# /nodes/
#----------
示例3: getallnodes
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import get [as 别名]
def getallnodes():
key_auth()
transform = lambda nl: [dict(node) for node in nl]
if not request.params.filter or request.params.filter == "all":
return {'data': transform(model.NodeList.get()) }
elif request.params.filter == "best":
return {'data': transform(model.NodeList.best()) }
elif request.params.filter == "alive":
return {'data': transform(model.NodeList.best()) }
elif request.params.filter == "down":
return {'data': transform(model.NodeList.down()) }
elif request.params.fitler == "disabled":
return {'data': transform(model.NodeList.disabled()) }
else:
abort(400, "Invalid filter")
示例4: main
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import get [as 别名]
def main():
print(banner)
global STATIC_PATH
# Get the hindsight module's path on disk to add to sys.path, so we can find templates and static files
module_path = os.path.dirname(pyhindsight.__file__)
sys.path.insert(0, module_path)
# Loop through all paths in system path, to pick up all potential locations for templates and static files.
# Paths can get weird when the program is run from a different directory, or when the packaged exe is unpacked.
for potential_path in sys.path:
potential_template_path = potential_path
if os.path.isdir(potential_template_path):
# Insert the current plugin location to the system path, so bottle can find the templates
bottle.TEMPLATE_PATH.insert(0, potential_template_path)
potential_static_path = os.path.join(potential_path, 'static')
if os.path.isdir(potential_static_path):
STATIC_PATH = potential_static_path
# webbrowser.open("http://localhost:8080")
bottle.run(host='localhost', port=8080, debug=True)
示例5: get_secret
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import get [as 别名]
def get_secret():
region = None
secret = None
import os
# get parms from env vars first
if _SECRET_NAME in os.environ:
secret = os.environ[_SECRET_NAME]
region = os.environ[_REGION]
else:
# otherwise, get from secret.ini
parser = ConfigParser.RawConfigParser()
p = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'conf', 'secret.ini')
parser.read(p)
region = parser.get('aws', 'region')
secret = parser.get('secret', 'var_name')
return _get_secret(secret, region)
示例6: change_password
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import get [as 别名]
def change_password(conf, *args):
try:
if conf.get('type') == 'ad':
change_password_ad(conf, *args)
else:
change_password_ldap(conf, *args)
except (LDAPBindError, LDAPInvalidCredentialsResult, LDAPUserNameIsMandatoryError):
raise Error('Username or password is incorrect!')
except LDAPConstraintViolationResult as e:
# Extract useful part of the error message (for Samba 4 / AD).
msg = e.message.split('check_password_restrictions: ')[-1].capitalize()
raise Error(msg)
except LDAPSocketOpenError as e:
LOG.error('{}: {!s}'.format(e.__class__.__name__, e))
raise Error('Unable to connect to the remote server.')
except LDAPExceptionError as e:
LOG.error('{}: {!s}'.format(e.__class__.__name__, e))
raise Error('Encountered an unexpected error while communicating with the remote server.')
示例7: get_next_page
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import get [as 别名]
def get_next_page(r):
link = r.headers.get('Link', None)
if not link:
return None
n1 = link.find('rel=\"next\"')
if n1 < 0:
return None
n2 = link.rfind('<', 0, n1)
if n2 < 0:
return None
n2 += 1
n3 = link.find('>;', n2)
return link[n2:n3]
示例8: fc_test
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import get [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
示例9: do_poem
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import get [as 别名]
def do_poem():
input_str= request.forms.get('input_str')
length= request.forms.get('length')
position= request.forms.get('position')
rtype= request.forms.get('type')
input_str_arg = "%s -l %s -p %s"%(input_str,length, position)
result = m.main(input_str_arg.split(),print_out=False)
if rtype == 'html':
return '''
<p>
原文: %s <br/>
</p><p>
詩: <br/> %s
</p>
<a href="./poem" >back</a>
'''%(input_str,result.encode('utf-8').replace('\n','<br/>'))
elif rtype == 'json':
return '''
%s
'''%(json.dumps({'input':input_str,'output':result.encode('utf-8').replace('\n',' ')}))
#if check_login(username, password):
示例10: edit
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import get [as 别名]
def edit():
#file_list = {
# 'filename1': 'path1',
# 'filename2': 'path2',
# 'dirname1': {
# 'filename3': 'path3',
# 'dirname2': {
# 'filename4': 'path4',
# 'filename5': 'path5'
# }
# }
#}
file_list = make_file_tree(ROOT)
file = request.GET.get('file')
if file:
with open(os.path.join(ROOT, file), 'r') as in_file:
code = in_file.read()
if file.split('.')[-1] in ['pyui', 'json']:
code = json.dumps(json.loads(code), indent=4, separators=(',', ': '))
output = template(os.path.join(IDE_REL_ROOT, 'main.tpl'), files = file_list, save_as = file, code = code)
else:
output = template(os.path.join(IDE_REL_ROOT, 'main.tpl'), files = file_list)
return output
示例11: get_preview_image
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import get [as 别名]
def get_preview_image():
context = get_label_context(request)
im = create_label_im(**context)
return_format = request.query.get('return_format', 'png')
if return_format == 'base64':
import base64
response.set_header('Content-type', 'text/plain')
return base64.b64encode(image_to_png_bytes(im))
else:
response.set_header('Content-type', 'image/png')
return image_to_png_bytes(im)
示例12: getSoftwares
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import get [as 别名]
def getSoftwares():
response.set_header("Access-Control-Allow-Origin", "*")
db = mariadb.connect(user=Settings.MONITOR_DB['user'], password=Settings.MONITOR_DB['password'], database=Settings.MONITOR_DB['database'])
softwares = collections.OrderedDict()
dateStart = request.GET.get('dateStart', str(date('%Y-%m-%d'))).strip()
dateEnd = request.GET.get('dateEnd', str(date('%Y-%m-%d'))).strip()
query = """SELECT *
FROM `softwares`
WHERE `dateStats` BETWEEN %s AND %s
ORDER BY `hits` DESC, `dateStats` ASC"""
results = db.cursor()
results.execute(query, (dateStart, dateEnd))
for row in results:
currentDate = row[2].strftime('%Y-%m-%d')
if not currentDate in softwares.keys():
softwares[currentDate] = collections.OrderedDict()
softwares[currentDate][str(row[0])] = str(row[1])
db.close()
return simplejson.dumps(softwares)
示例13: getSchemas
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import get [as 别名]
def getSchemas():
response.set_header("Access-Control-Allow-Origin", "*")
db = mariadb.connect(user=Settings.MONITOR_DB['user'], password=Settings.MONITOR_DB['password'], database=Settings.MONITOR_DB['database'])
#db.text_factory = lambda x: unicode(x, "utf-8", "ignore")
schemas = collections.OrderedDict()
dateStart = request.GET.get('dateStart', str(date('%Y-%m-%d'))).strip()
dateEnd = request.GET.get('dateEnd', str(date('%Y-%m-%d'))).strip()
query = """SELECT *
FROM `schemas`
WHERE `dateStats` BETWEEN %s AND %s
ORDER BY `hits` DESC, `dateStats` ASC"""
results = db.cursor()
results.execute(query, (dateStart, dateEnd))
for row in results:
currentDate = row[2].strftime('%Y-%m-%d')
if not currentDate in schemas.keys():
schemas[currentDate] = collections.OrderedDict()
schemas[currentDate][str(row[0])] = str(row[1])
db.close()
return simplejson.dumps(schemas)
示例14: get_remote_address
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import get [as 别名]
def get_remote_address():
"""
Determines the address of the uploading client. First checks the for
proxy-forwarded headers, then falls back to request.remote_addr.
:rtype: str
"""
return request.headers.get('X-Forwarded-For', request.remote_addr)
示例15: putisk
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import get [as 别名]
def putisk(name):
key_auth("billing")
if 'isk' not in request.forms:
abort(400, "Must include 'isk'")
try:
user = model.User.get(name)
isk = int(request.forms.isk)
user.credit_isk += isk
user.save()
return str(user.credit_isk)
except ValueError as ve:
abort(errstatus(ve), ve.message)