setting.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # -*- coding: utf-8 -*-
  2. """
  3. -------------------------------------------------
  4. File Name: setting.py
  5. Description : 配置文件
  6. Author : JHao
  7. date: 2019/2/15
  8. -------------------------------------------------
  9. Change Activity:
  10. 2019/2/15:
  11. -------------------------------------------------
  12. """
  13. import sys
  14. from os import getenv
  15. from logging import getLogger
  16. log = getLogger(__name__)
  17. HEADER = """
  18. ****************************************************************
  19. *** ______ ********************* ______ *********** _ ********
  20. *** | ___ \_ ******************** | ___ \ ********* | | ********
  21. *** | |_/ / \__ __ __ _ __ _ | |_/ /___ * ___ | | ********
  22. *** | __/| _// _ \ \ \/ /| | | || __// _ \ / _ \ | | ********
  23. *** | | | | | (_) | > < \ |_| || | | (_) | (_) || |___ ****
  24. *** \_| |_| \___/ /_/\_\ \__ |\_| \___/ \___/ \_____/ ****
  25. **** __ / / *****
  26. ************************* /___ / *******************************
  27. ************************* ********************************
  28. ****************************************************************
  29. """
  30. PY3 = sys.version_info >= (3,)
  31. DB_TYPE = getenv('db_type', 'SSDB').upper()
  32. DB_HOST = getenv('db_host', '127.0.0.1')
  33. DB_PORT = getenv('db_port', 8888)
  34. DB_PASSWORD = getenv('db_password', '')
  35. """ 数据库配置 """
  36. DATABASES = {
  37. "default": {
  38. "TYPE": DB_TYPE,
  39. "HOST": DB_HOST,
  40. "PORT": DB_PORT,
  41. "NAME": "proxy",
  42. "PASSWORD": DB_PASSWORD
  43. }
  44. }
  45. # register the proxy getter function
  46. PROXY_GETTER = [
  47. "freeProxy01",
  48. # "freeProxy02",
  49. "freeProxy03",
  50. "freeProxy04",
  51. "freeProxy05",
  52. # "freeProxy06",
  53. "freeProxy07",
  54. # "freeProxy08",
  55. "freeProxy09",
  56. "freeProxy13",
  57. "freeProxy14",
  58. "freeProxy14",
  59. ]
  60. """ API config http://127.0.0.1:5010 """
  61. SERVER_API = {
  62. "HOST": "0.0.0.0", # The ip specified which starting the web API
  63. "PORT": 5010 # port number to which the server listens to
  64. }
  65. VERIFY_HOST = getenv('proxy_verify_host', 'http://www.baidu.com')
  66. class ConfigError(BaseException):
  67. pass
  68. def checkConfig():
  69. if DB_TYPE not in ["SSDB", "REDIS"]:
  70. raise ConfigError('db_type Do not support: %s, must SSDB/REDIS .' % DB_TYPE)
  71. if type(DB_PORT) == str and not DB_PORT.isdigit():
  72. raise ConfigError('if db_port is string, it must be digit, not %s' % DB_PORT)
  73. from ProxyGetter import getFreeProxy
  74. illegal_getter = list(filter(lambda key: not hasattr(getFreeProxy.GetFreeProxy, key), PROXY_GETTER))
  75. if len(illegal_getter) > 0:
  76. raise ConfigError("ProxyGetter: %s does not exists" % "/".join(illegal_getter))
  77. checkConfig()