From c0f2ac98477665e42a65db8c594fe3a2b0421c63 Mon Sep 17 00:00:00 2001 From: lzybetter Date: Sat, 9 Sep 2023 14:54:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 6 ++++++ util/config.py | 12 ++++++++++++ util/requests_with_proxy.py | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4899128..789ef31 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,12 @@ test.py *.yaml *.db +## user file +token_cache.bin + +### plugin file +custom_plugins/* + ### venv template # Virtualenv # http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ diff --git a/util/config.py b/util/config.py index 3311559..431faad 100644 --- a/util/config.py +++ b/util/config.py @@ -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)) \ No newline at end of file diff --git a/util/requests_with_proxy.py b/util/requests_with_proxy.py index f068a73..c8e7e45 100644 --- a/util/requests_with_proxy.py +++ b/util/requests_with_proxy.py @@ -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)