run_server.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. 'gift',
  21. 'change_password']
  22. @route('/<path>', method='POST')
  23. def process(path):
  24. path = path.strip().lower()
  25. if path not in valid_routes:
  26. return not_found()
  27. response.content_type = 'application/json'
  28. method_to_call = getattr(server_controller, path)
  29. try:
  30. model.drop_expired_orders()
  31. resp = method_to_call()
  32. if response.status_code == 200:
  33. model.connection.commit()
  34. else:
  35. model.connection.rollback()
  36. return resp
  37. except sqlite3.IntegrityError as e:
  38. print(e)
  39. model.connection.rollback()
  40. return server_controller.bad_request('Action violates database constraints.')
  41. @route('/', method='GET')
  42. def process():
  43. redirect('http://koljastrohm-games.com/downloads/orderer_installer.zip')
  44. run(host='0.0.0.0', port=connection.port, debug=debug)
  45. model.connection.close()