You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
1.9 KiB
102 lines
1.9 KiB
#! /usr/bin/python3 |
|
# -*- coding:utf-8 -*- |
|
import bottle as b |
|
import os |
|
from . import CURRENT_DIR, lottery |
|
|
|
app = b.Bottle() |
|
|
|
|
|
@app.route('/') |
|
def index(): |
|
return b.static_file('index.html', os.path.join(CURRENT_DIR, "templates")) |
|
|
|
|
|
@app.route('/update', method='POST') |
|
def update(): |
|
b.abort(403) |
|
|
|
|
|
@app.route('/revoke') |
|
def revoke(): |
|
uid = b.request.params.get('uid') |
|
if not uid: |
|
b.abort(403) |
|
return lottery.revoke(id) |
|
|
|
|
|
@app.route('/users') |
|
def users(): |
|
return lottery.users() |
|
|
|
|
|
@app.route('/lucky_users') |
|
def lucky_users(): |
|
award_id = b.request.params.get('award_id') |
|
return lottery.lucky_users(award_id) |
|
|
|
|
|
@app.route('/luckless_users') |
|
def luckless_users(): |
|
return lottery.luckless_users() |
|
|
|
|
|
@app.route('/awards') |
|
def awards(): |
|
return lottery.awards() |
|
|
|
|
|
@app.route('/award') |
|
def award(): |
|
award_id = b.request.params.get('award_id') |
|
if award_id is None: |
|
b.abort(403) |
|
if type(award_id) is not int: |
|
award_id = int(award_id) |
|
return lottery.award(award_id) |
|
|
|
|
|
@app.route('/add_awards', method='POST') |
|
def add_awards(): |
|
return lottery.add_awards(b.request.json['awards']) |
|
|
|
|
|
@app.route('/reset') |
|
def reset(): |
|
return lottery.reset() |
|
|
|
|
|
@app.route('/run') |
|
def run(): |
|
return lottery.run() |
|
|
|
|
|
@app.route('/draw_lottery') |
|
def draw_lottery(): |
|
award_id = b.request.params.get('award_id') |
|
if award_id is None: |
|
b.abort(403) |
|
return lottery.draw_lottery(award_id) |
|
|
|
|
|
@app.route('/static/<filepath:path>') |
|
def callback(filepath): |
|
return b.static_file(filepath, os.path.join(CURRENT_DIR, "static")) |
|
|
|
|
|
@app.route('/templates/<filepath:path>') |
|
def callback(filepath): |
|
return b.static_file(filepath, os.path.join(CURRENT_DIR, "templates")) |
|
|
|
|
|
@b.error |
|
def error403(error): |
|
return "非法访问 " + error |
|
|
|
|
|
def run(host, port, debug): |
|
app.run(host=host, port=port, debug=debug) |
|
|
|
|
|
if __name__ == '__main__': |
|
run('localhost', 8080, True)
|
|
|