setting.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. PY3 = sys.version_info >= (3,)
  28. DB_TYPE = getenv('db_type', 'SSDB').upper()
  29. DB_HOST = getenv('db_host', '127.0.0.1')
  30. DB_PORT = getenv('db_port', '8080')
  31. DB_PASSWORD = getenv('db_password', '')
  32. """ 数据库配置 """
  33. DATABASES = {
  34. "default": {
  35. "TYPE": "REDIS",
  36. "HOST": "19.19.22.54",
  37. "PORT": "6379",
  38. "NAME": "proxy",
  39. "PASSWORD": "_@Fintell"
  40. }
  41. }
  42. # register the proxy getter function
  43. PROXY_GETTER = [
  44. "freeProxy01",
  45. "freeProxy02",
  46. "freeProxy03",
  47. "freeProxy04",
  48. "freeProxy05",
  49. "freeProxy06",
  50. "freeProxy07",
  51. "freeProxy08",
  52. "freeProxy09",
  53. ]
  54. """ API config http://127.0.0.1:5010 """
  55. SERVER_API = {
  56. "HOST": "0.0.0.0", # The ip specified which starting the web API
  57. "PORT": 5010 # port number to which the server listens to
  58. }
  59. class ConfigError(BaseException):
  60. pass
  61. def checkConfig():
  62. if DB_TYPE not in ["SSDB", "REDIS"]:
  63. raise ConfigError('db_type Do not support: %s, must SSDB/REDIS .' % DB_TYPE)
  64. if not DB_PORT.isdigit():
  65. raise ConfigError('db_port must be digit, not %s' % DB_PORT)
  66. from ProxyGetter import getFreeProxy
  67. illegal_getter = list(filter(lambda key: not hasattr(getFreeProxy.GetFreeProxy, key), PROXY_GETTER))
  68. if len(illegal_getter) > 0:
  69. raise ConfigError("ProxyGetter: %s does not exists" % "/".join(illegal_getter))
  70. checkConfig()