setting.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import platform
  2. from os.path import dirname, abspath, join
  3. from environs import Env
  4. from loguru import logger
  5. env = Env()
  6. env.read_env()
  7. # definition of flags
  8. IS_WINDOWS = platform.system().lower() == 'windows'
  9. # definition of dirs
  10. ROOT_DIR = dirname(dirname(abspath(__file__)))
  11. LOG_DIR = join(ROOT_DIR, env.str('LOG_DIR', 'logs'))
  12. # definition of environments
  13. DEV_MODE, TEST_MODE, PROD_MODE = 'dev', 'test', 'prod'
  14. APP_ENV = env.str('APP_ENV', DEV_MODE).lower()
  15. APP_DEBUG = env.bool('APP_DEBUG', True if APP_ENV == DEV_MODE else False)
  16. APP_DEV = IS_DEV = APP_ENV == DEV_MODE
  17. APP_PROD = IS_PROD = APP_DEV == PROD_MODE
  18. APP_TEST = IS_TEST = APP_ENV = TEST_MODE
  19. # redis host
  20. REDIS_HOST = env.str('REDIS_HOST', '127.0.0.1')
  21. # redis port
  22. REDIS_PORT = env.int('REDIS_PORT', 6379)
  23. # redis password, if no password, set it to None
  24. REDIS_PASSWORD = env.str('REDIS_PASSWORD', None)
  25. # redis connection string, like redis://[password]@host:port or rediss://[password]@host:port
  26. # REDIS_CONNECTION_STRING = env.str('REDIS_CONNECTION_STRING', None)
  27. # if REDIS_CONNECTION_STRING:
  28. # REDIS_HOST, REDIS_PORT, REDIS_PASSWORD = parse_redis_connection_string(REDIS_CONNECTION_STRING)
  29. # redis hash table key name
  30. REDIS_KEY = env.str('REDIS_KEY', 'proxies:universal')
  31. # definition of proxy scores
  32. PROXY_SCORE_MAX = 100
  33. PROXY_SCORE_MIN = 0
  34. PROXY_SCORE_INIT = 10
  35. # definition of proxy number
  36. PROXY_NUMBER_MAX = 50000
  37. PROXY_NUMBER_MIN = 0
  38. # definition of tester cycle, it will test every CYCLE_TESTER second
  39. CYCLE_TESTER = env.int('CYCLE_TESTER', 20)
  40. # definition of getter cycle, it will get proxy every CYCLE_GETTER second
  41. CYCLE_GETTER = env.int('CYCLE_GETTER', 100)
  42. # definition of tester
  43. TEST_URL = env.str('TEST_URL', 'http://www.baidu.com')
  44. TEST_TIMEOUT = env.int('TEST_TIMEOUT', 10)
  45. TEST_BATCH = env.int('TEST_BATCH', 20)
  46. # TEST_HEADERS = env.json('TEST_HEADERS', {
  47. # 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36',
  48. # })
  49. TEST_VALID_STATUS = env.list('TEST_VALID_STATUS', [200, 206, 302])
  50. # definition of api
  51. API_HOST = env.str('API_HOST', '0.0.0.0')
  52. API_PORT = env.int('API_PORT', 5555)
  53. API_THREADED = env.bool('API_THREADED', True)
  54. # flags of enable
  55. ENABLE_TESTER = env.bool('ENABLE_TESTER', True)
  56. ENABLE_GETTER = env.bool('ENABLE_GETTER', True)
  57. ENABLE_SERVER = env.bool('ENABLE_SERVER', True)
  58. logger.add(env.str('LOG_RUNTIME_FILE', 'runtime.log'), level='DEBUG', rotation='1 week', retention='20 days')
  59. logger.add(env.str('LOG_ERROR_FILE', 'error.log'), level='ERROR', rotation='1 week')