123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import sqlite3
- import connection
- import server_controller
- import model
- from bottle import run, response, route
- from server_controller import not_found
- from util import debug
- if __name__ == '__main__':
- print('sqlite3.version', model.db.version)
- valid_routes = ['login',
- 'register',
- 'depot',
- 'activate_key',
- 'order', 'orders',
- 'news',
- 'transactions',
- 'orders_on',
- 'cancel_order',
- 'leaderboard']
- @route('/<path>', method='POST')
- def process(path):
- path = path.strip().lower()
- if path not in valid_routes:
- return not_found()
- response.content_type = 'application/json'
- method_to_call = getattr(server_controller, path)
- try:
- model.drop_expired_orders()
- resp = method_to_call()
- if response.status_code == 200:
- model.connection.commit()
- else:
- model.connection.rollback()
- return resp
- except sqlite3.IntegrityError as e:
- print(e)
- model.connection.rollback()
- return server_controller.bad_request('Action violates database constraints.')
- run(host='0.0.0.0', port=connection.port, debug=debug)
- model.connection.close()
|