1
1

run_server.py 1.8 KB

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