app.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # File : app.py
  4. # Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
  5. # Date : 2022/9/6
  6. from flask.app import Flask
  7. from flask_migrate import Migrate
  8. from base import config
  9. from base.database import db
  10. from utils.log import logger
  11. from utils.system import get_wlan_info,getHost
  12. from controllers import *
  13. from js.rules import getRuleLists
  14. import sys
  15. def create_flask_app():
  16. app = Flask(__name__, static_folder='static', static_url_path='/static')
  17. app.config.from_object(config) # 单独的配置文件里写了,这里就不用弄json中文显示了
  18. app.register_blueprint(home.home, url_prefix='')
  19. app.register_blueprint(admin.admin, url_prefix='/admin')
  20. app.register_blueprint(vod.vod, url_prefix='')
  21. app.register_blueprint(cls.cls, url_prefix='/cls')
  22. app.register_blueprint(layui.layui, url_prefix='/layui')
  23. app.register_blueprint(parse.parse, url_prefix='/parse')
  24. app.logger.name = "drLogger"
  25. # lsg = service.storage_service()
  26. logger.info(f"默认解析地址:{app.config.get('PLAY_URL')}")
  27. # logger.info(f"自定义播放解析地址:{lsg.getItem('PLAY_URL')}")
  28. logger.info(f'当前操作系统{sys.platform}')
  29. rule_list = getRuleLists()
  30. wlan_info,_ = get_wlan_info()
  31. logger.info(rule_list)
  32. logger.info(f'局域网: {getHost(1, app.config.get("HTTP_PORT"))}/index\n本地: {getHost(0, app.config.get("HTTP_PORT"))}/index\nwlan_info:{wlan_info}')
  33. db.init_app(app)
  34. db.app = app
  35. db.create_all(app=app)
  36. return app
  37. app = create_flask_app()
  38. migrate = Migrate(app, db)
  39. now_python_ver = ".".join([str(i) for i in sys.version_info[:3]])
  40. if sys.version_info < (3,9):
  41. from gevent.pywsgi import WSGIServer
  42. # from gevent import monkey
  43. # monkey.patch_socket() # 开启socket异步
  44. print(f'当前python版本{now_python_ver}为3.9.0及以下,支持gevent')
  45. else:
  46. print(f'当前python版本{now_python_ver}为3.9.0及以上,不支持gevent')
  47. if __name__ == "__main__":
  48. http_port = int(app.config.get('HTTP_PORT', 5705))
  49. http_host = app.config.get('HTTP_HOST', '0.0.0.0')
  50. if sys.version_info < (3, 9):
  51. # server = WSGIServer(('0.0.0.0', 5705), app, handler_class=WebSocketHandler,log=app.logger)
  52. # server = WSGIServer(('0.0.0.0', 5705), app, handler_class=WebSocketHandler,log=None)
  53. server = WSGIServer((http_host, http_port), app, log=logger)
  54. server.serve_forever()
  55. else:
  56. app.run(debug=False, host=http_host, port=http_port)