Просмотр исходного кода

Merge pull request #68 from kangnwh/master

add configuration for host ip & port
J_hao104 9 лет назад
Родитель
Сommit
cfc29ee29e
4 измененных файлов с 20 добавлено и 3 удалено
  1. 3 1
      Api/ProxyApi.py
  2. 4 0
      Config.ini
  3. 4 2
      Run/main.py
  4. 9 0
      Util/GetConfig.py

+ 3 - 1
Api/ProxyApi.py

@@ -16,6 +16,7 @@ __author__ = 'JHao'
 import sys
 
 from flask import Flask, jsonify, request
+from Util.GetConfig import GetConfig
 
 sys.path.append('../')
 
@@ -71,7 +72,8 @@ def get_status():
 
 
 def run():
-    app.run(host='0.0.0.0', port=5000)
+    config = GetConfig()
+    app.run(host=config.host_ip, port=config.host_port)
 
 if __name__ == '__main__':
     run()

+ 4 - 0
Config.ini

@@ -13,3 +13,7 @@ freeProxySecond = 1
 freeProxyThird  = 1
 freeProxyFourth = 1
 freeProxyFifth  = 1
+
+[HOST]
+ip = 0.0.0.0
+port = 5010

+ 4 - 2
Run/main.py

@@ -15,12 +15,13 @@ __author__ = 'JHao'
 import sys
 from multiprocessing import Process
 
+
 sys.path.append('../')
 
 from Api.ProxyApi import run as ProxyApiRun
 from Schedule.ProxyValidSchedule import run as ValidRun
 from Schedule.ProxyRefreshSchedule import run as RefreshRun
-
+from Util.GetConfig import GetConfig
 
 def run():
     p_list = list()
@@ -30,10 +31,11 @@ def run():
     p_list.append(p2)
     p3 = Process(target=RefreshRun, name='RefreshRun')
     p_list.append(p3)
+
     for p in p_list:
         p.start()
     for p in p_list:
         p.join()
 
 if __name__ == '__main__':
-    run()
+   run()

+ 9 - 0
Util/GetConfig.py

@@ -49,6 +49,13 @@ class GetConfig(object):
     def proxy_getter_functions(self):
         return self.config_file.options('ProxyGetter')
 
+    @LazyProperty
+    def host_ip(self):
+        return self.config_file.get('HOST','ip')
+
+    @LazyProperty
+    def host_port(self):
+        return self.config_file.get('HOST', 'port')
 
 if __name__ == '__main__':
     gg = GetConfig()
@@ -57,3 +64,5 @@ if __name__ == '__main__':
     print(gg.db_host)
     print(gg.db_port)
     print(gg.proxy_getter_functions)
+    print(gg.host_ip)
+    print(gg.host_port)