Przeglądaj źródła

[update] 使用setting.py替换Config.ini配置文件

jhao 7 lat temu
rodzic
commit
16c5a04ba4
5 zmienionych plików z 7 dodań i 114 usunięć
  1. 0 35
      Config.ini
  2. 1 1
      Config/setting.py
  3. 1 1
      Test/testConfig.py
  4. 5 6
      Test/testGetFreeProxy.py
  5. 0 71
      Util/GetConfig.py

+ 0 - 35
Config.ini

@@ -1,35 +0,0 @@
-[DB]
-;Configure the database information
-;type: SSDB/MONGODB if use redis, only modify the host port, the type should be SSDB
-type = SSDB
-host = 127.0.0.1
-port = 8888
-name = proxy
-;username = your_username (Only Mongodb)
-;password = your_password
-
-[ProxyGetter]
-;register the proxy getter function
-freeProxyFirst = 1
-freeProxySecond = 1
-;freeProxyThird  = 1
-freeProxyFourth = 1
-freeProxyFifth = 1
-;freeProxySixth = 1
-freeProxySeventh = 1
-;freeProxyEight = 1
-;freeProxyNinth = 1
-freeProxyTen = 1
-freeProxyEleven = 1
-freeProxyTwelve = 1
-;foreign website, outside the wall
-;freeProxyWallFirst = 1
-;freeProxyWallSecond = 1
-;freeProxyWallThird = 1
-
-[API]
-# API config http://127.0.0.1:5010
-# The ip specified when starting the web API
-ip = 0.0.0.0
-# he port on which to run the web API
-port = 8080

+ 1 - 1
Config/setting.py

@@ -51,4 +51,4 @@ PROXY_GETTER = [
 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
-}
+}

+ 1 - 1
Test/testConfig.py

@@ -2,7 +2,7 @@
 """
 -------------------------------------------------
    File Name:     testGetConfig
-   Description :   test all function in GetConfig.py
+   Description :   testGetConfig
    Author :        J_hao
    date:          2017/7/31
 -------------------------------------------------

+ 5 - 6
Test/testGetFreeProxy.py

@@ -16,7 +16,6 @@ import re
 import sys
 import requests
 
-
 try:
     from importlib import reload  # py3 实际不会实用,只是为了不显示语法错误
 except:
@@ -25,7 +24,7 @@ except:
 
 sys.path.append('..')
 from ProxyGetter.getFreeProxy import GetFreeProxy
-from Util.GetConfig import GetConfig
+from Config.ConfigGetter import config
 
 
 # noinspection PyPep8Naming
@@ -34,15 +33,15 @@ def testGetFreeProxy():
     test class GetFreeProxy in ProxyGetter/GetFreeProxy
     :return:
     """
-    gc = GetConfig()
-    proxy_getter_functions = gc.proxy_getter_functions
+    proxy_getter_functions = config.proxy_getter_functions
     for proxyGetter in proxy_getter_functions:
         proxy_count = 0
         for proxy in getattr(GetFreeProxy, proxyGetter.strip())():
             if proxy:
-                print('{func}: fetch proxy {proxy},proxy_count:{proxy_count}'.format(func=proxyGetter, proxy=proxy,proxy_count=proxy_count))
+                print('{func}: fetch proxy {proxy},proxy_count:{proxy_count}'.format(func=proxyGetter, proxy=proxy,
+                                                                                     proxy_count=proxy_count))
                 proxy_count += 1
-        #assert proxy_count >= 20, '{} fetch proxy fail'.format(proxyGetter)
+        # assert proxy_count >= 20, '{} fetch proxy fail'.format(proxyGetter)
 
 
 if __name__ == '__main__':

+ 0 - 71
Util/GetConfig.py

@@ -1,71 +0,0 @@
-# -*- coding: utf-8 -*-
-# !/usr/bin/env python
-"""
--------------------------------------------------
-   File Name:     GetConfig.py
-   Description :  fetch config from config.ini
-   Author :       JHao
-   date:          2016/12/3
--------------------------------------------------
-   Change Activity:
-                   2016/12/3: get db property func
--------------------------------------------------
-"""
-__author__ = 'JHao'
-
-from Util.utilClass import LazyProperty
-
-
-class GetConfig(object):
-    """
-    to get config from config.ini
-    """
-
-    def __init__(self):
-        pass
-
-    @LazyProperty
-    def db_type(self):
-        return self.config_file.get('DB', 'type')
-
-    @LazyProperty
-    def db_name(self):
-        return self.config_file.get('DB', 'name')
-
-    @LazyProperty
-    def db_host(self):
-        return self.config_file.get('DB', 'host')
-
-    @LazyProperty
-    def db_port(self):
-        return int(self.config_file.get('DB', 'port'))
-
-    @LazyProperty
-    def db_password(self):
-        return self.config_file.get('DB', 'password')
-
-    @LazyProperty
-    def proxy_getter_functions(self):
-        return self.config_file.options('ProxyGetter')
-
-    @LazyProperty
-    def host_ip(self):
-        return self.config_file.get('API', 'ip')
-
-    @LazyProperty
-    def host_port(self):
-        return int(self.config_file.get('API', 'port'))
-
-
-config = GetConfig()
-
-if __name__ == '__main__':
-    gg = GetConfig()
-    print(gg.db_type)
-    print(gg.db_name)
-    print(gg.db_host)
-    print(gg.db_port)
-    print(gg.proxy_getter_functions)
-    print(gg.host_ip)
-    print(gg.host_port)
-    print(gg.db_password)