osc/deploy/ProxyPool/Config/setting.py
2025-05-28 19:16:17 +08:00

99 lines
3.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name setting.py
Description : 配置文件
Author : JHao
date 2019/2/15
-------------------------------------------------
Change Activity:
2019/2/15:
-------------------------------------------------
"""
import sys
from os import getenv
from logging import getLogger
log = getLogger(__name__)
HEADER = """
****************************************************************
*** ______ ********************* ______ *********** _ ********
*** | ___ \_ ******************** | ___ \ ********* | | ********
*** | |_/ / \__ __ __ _ __ _ | |_/ /___ * ___ | | ********
*** | __/| _// _ \ \ \/ /| | | || __// _ \ / _ \ | | ********
*** | | | | | (_) | > < \ |_| || | | (_) | (_) || |___ ****
*** \_| |_| \___/ /_/\_\ \__ |\_| \___/ \___/ \_____/ ****
**** __ / / *****
************************* /___ / *******************************
************************* ********************************
****************************************************************
"""
PY3 = sys.version_info >= (3,)
DB_TYPE = getenv('db_type', 'REDIS').upper()
DB_HOST = getenv('db_host', '107.182.191.3')
DB_PORT = getenv('db_port', 7379)
DB_PASSWORD = getenv('db_password', 'jlkj-841-2-redis')
USEFUL_PROXY_COUNT = 10
ZHIMA_PROXY_API = 'http://http.tiqu.alicdns.com/getip3?num=10&type=2&pro=0&city=0&yys=0&port=1&time=1&ts=0&ys=0&cs=0&lb=1&sb=0&pb=45&mr=2&regions=&gm=4'
# ZHIMA_PROXY_API = 'http://api.proxy.ipidea.io/getProxyIp?num=10&return_type=json&lb=1&sb=0&flow=1&regions=&protocol=http'
""" 数据库配置 """
DATABASES = {
"default": {
"TYPE": DB_TYPE,
"HOST": DB_HOST,
"PORT": DB_PORT,
"NAME": "proxy",
"PASSWORD": DB_PASSWORD
}
}
# register the proxy getter function
PROXY_GETTER = [
# # "freeProxy01",
# "freeProxy02",
# "freeProxy03",
# "freeProxy04",
# "freeProxy05",
# # "freeProxy06",
# "freeProxy07",
# # "freeProxy08",
# "freeProxy09",
# "freeProxy13",
# #"freeProxy14",
# "freeProxy15",
"zhimaProxy"
]
""" API config http://127.0.0.1:5010 """
SERVER_API = {
"HOST": "0.0.0.0", # The ip specified which starting the web API
"PORT": 5010 # port number to which the server listens to
}
class ConfigError(BaseException):
pass
def checkConfig():
if DB_TYPE not in ["SSDB", "REDIS"]:
raise ConfigError('db_type Do not support: %s, must SSDB/REDIS .' % DB_TYPE)
if type(DB_PORT) == str and not DB_PORT.isdigit():
raise ConfigError('if db_port is string, it must be digit, not %s' % DB_PORT)
from ProxyGetter import getFreeProxy
illegal_getter = list(filter(lambda key: not hasattr(getFreeProxy.GetFreeProxy, key), PROXY_GETTER))
if len(illegal_getter) > 0:
raise ConfigError("ProxyGetter: %s does not exists" % "/".join(illegal_getter))
checkConfig()