测试插件

This commit is contained in:
lzybetter
2023-09-09 14:54:25 +08:00
parent 1bd2a9dbc2
commit c0f2ac9847
3 changed files with 19 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ import os
class Config:
__BASE_PATH = os.getcwd()
__CONFIG_PATH = os.path.join(__BASE_PATH, 'config')
__CONFIG_NAME = 'test.yaml'
@@ -61,3 +62,14 @@ class Config:
self.__CONFIG_DICT['PROXY'] = new_proxy
with open(os.path.join(self.__CONFIG_PATH, self.__CONFIG_NAME), 'w') as f:
f.write(yaml.safe_dump(self.__CONFIG_DICT, sort_keys=False))
def get_config(self, config_name, default=None):
try:
return self.__CONFIG_DICT[config_name]
except:
return default
def set_config(self, config_name, value):
self.__CONFIG_DICT[config_name] = value
with open(os.path.join(self.__CONFIG_PATH, self.__CONFIG_NAME), 'w') as f:
f.write(yaml.safe_dump(self.__CONFIG_DICT, sort_keys=False))

View File

@@ -34,7 +34,7 @@ class RequestWithProxy:
def get(self, url, headers=None):
try:
if url.replace("https://", "").replace("http://", "") in self.__no_proxy:
if url.replace("https://", "").replace("http://", "").splice('/')[0] in self.__no_proxy:
r = requests.get(url=url, headers=headers)
else:
r = requests.get(url=url, headers=headers, proxies=self.__proxies)