import sqlite3 import time from bottle import run, response, route, redirect import connection import model import server_controller import trading_bot from debug import debug from server_controller import not_found if __name__ == '__main__': print('sqlite3.version', model.db.version) model.connect() valid_routes = ['login', 'register', 'depot', 'activate_key', 'order', 'orders', 'news', 'trades', 'trades_on', 'orders_on', 'old_orders', 'cancel_order', 'leaderboard', 'tradables', 'gift', 'change_password'] @route('/', method='POST') def process(path): start = time.clock() path = path.strip().lower() if path not in valid_routes: print('Processing time:', time.clock() - start) return not_found() response.content_type = 'application/json' method_to_call = getattr(server_controller, path) try: expired_orders = model.drop_expired_orders() trading_bot.notify_expired_orders(expired_orders) resp = method_to_call() if response.status_code == 200: model.connection.commit() else: model.connection.rollback() print('Processing time:', time.clock() - start) return resp except sqlite3.IntegrityError as e: print(e) model.connection.rollback() print('Processing time:', time.clock() - start) return server_controller.internal_server_error('Action violates database constraints.') @route('/', method='GET') def process(): redirect('http://koljastrohm-games.com/downloads/orderer_installer.zip') run(host='0.0.0.0', port=connection.port, debug=debug) model.connection.close()