run_server.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import sqlite3
  2. import connection
  3. import server_controller
  4. import model
  5. from bottle import run, response, route, redirect
  6. from server_controller import not_found
  7. from debug import debug
  8. if __name__ == '__main__':
  9. print('sqlite3.version', model.db.version)
  10. valid_routes = ['login',
  11. 'register',
  12. 'depot',
  13. 'activate_key',
  14. 'order', 'orders',
  15. 'news',
  16. 'transactions',
  17. 'orders_on',
  18. 'cancel_order',
  19. 'leaderboard',
  20. 'tradables',
  21. 'gift',
  22. 'change_password']
  23. @route('/<path>', method='POST')
  24. def process(path):
  25. path = path.strip().lower()
  26. if path not in valid_routes:
  27. return not_found()
  28. response.content_type = 'application/json'
  29. method_to_call = getattr(server_controller, path)
  30. try:
  31. model.drop_expired_orders()
  32. resp = method_to_call()
  33. if response.status_code == 200:
  34. model.connection.commit()
  35. else:
  36. model.connection.rollback()
  37. return resp
  38. except sqlite3.IntegrityError as e:
  39. print(e)
  40. model.connection.rollback()
  41. return server_controller.bad_request('Action violates database constraints.')
  42. @route('/', method='GET')
  43. def process():
  44. redirect('http://koljastrohm-games.com/downloads/orderer_installer.zip')
  45. run(host='0.0.0.0', port=connection.port, debug=debug)
  46. model.connection.close()