Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #36 from shing-yu/feature/忽略代理
Browse files Browse the repository at this point in the history
feat: 忽略系统代理设置
  • Loading branch information
shing-yu authored Dec 19, 2023
2 parents 315b049 + 72660cd commit a046595
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/fanqie_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ def fanqie_d(url, encoding, user_agent, path_choice, data_folder, start_chapter_
headers = {
"User-Agent": user_agent
}
proxies = {
"http": None,
"https": None
}

# 获取网页源码
try:
response = requests.get(url, headers=headers, timeout=20)
response = requests.get(url, headers=headers, timeout=20, proxies=proxies)
except Timeout:
print(Fore.RED + Style.BRIGHT + "连接超时,请检查网络连接是否正常。")
return
Expand Down Expand Up @@ -178,7 +182,7 @@ def fanqie_d(url, encoding, user_agent, path_choice, data_folder, start_chapter_
while retry_count < 4: # 设置最大重试次数
try:
# 获取 api 响应
api_response = requests.get(api_url, headers=headers, timeout=5)
api_response = requests.get(api_url, headers=headers, timeout=5, proxies=proxies)

tqdm.write(Fore.YELLOW + Style.BRIGHT + f"[DEBUG]HTTP状态码:{api_response}")

Expand Down
8 changes: 6 additions & 2 deletions src/fanqie_epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ def fanqie_epub(url, user_agent, path_choice):

# 创建epub电子书
book = epub.EpubBook()
proxies = {
"http": None,
"https": None
}

# 获取网页源码
try:
response = requests.get(url, headers=headers, timeout=20)
response = requests.get(url, headers=headers, timeout=20, proxies=proxies)
except Timeout:
print(Fore.RED + Style.BRIGHT + "连接超时,请检查网络连接是否正常。")
return
Expand Down Expand Up @@ -194,7 +198,7 @@ def fanqie_epub(url, user_agent, path_choice):
while retry_count < 4: # 设置最大重试次数
try:
# 获取 api 响应
api_response = requests.get(api_url, headers=headers, timeout=5)
api_response = requests.get(api_url, headers=headers, timeout=5, proxies=proxies)

# 解析 api 响应为 json 数据
api_data = api_response.json()
Expand Down
16 changes: 10 additions & 6 deletions src/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
os.makedirs(data_path, exist_ok=True)
book_id = None
start_chapter_id = "0"
proxies = {
"http": None,
"https": None
}


# 用户须知
Expand Down Expand Up @@ -167,7 +171,7 @@ def start():
clear_screen()
contributors_url = 'https://gitee.com/xingyv1024/fanqie-novel-download/raw/main/CONTRIBUTORS.md'
try:
contributors = requests.get(contributors_url, timeout=5)
contributors = requests.get(contributors_url, timeout=5, proxies=proxies)

# 检查响应状态码
if contributors.status_code == 200:
Expand Down Expand Up @@ -478,7 +482,7 @@ def check_update(now_version):
# noinspection PyBroadException
try:
# 发送GET请求以获取最新的发行版信息
response = requests.get(api_url, timeout=5)
response = requests.get(api_url, timeout=5, proxies=proxies)

if response.status_code != 200:
print(f"请求失败,状态码:{response.status_code}")
Expand Down Expand Up @@ -536,7 +540,7 @@ def check_eula():
eula_date_old = eula_txt.splitlines()[5]
# noinspection PyBroadException
try:
eula_text = requests.get(eula_url, timeout=10).text
eula_text = requests.get(eula_url, timeout=10, proxies=proxies).text
except Exception:
print("获取最终用户许可协议失败,请检查网络连接")
input("按Enter键继续...\n")
Expand Down Expand Up @@ -582,9 +586,9 @@ def check_eula():
def agree_eula():
# noinspection PyBroadException
try:
eula_text = requests.get(eula_url, timeout=10).text
license_text = requests.get(license_url, timeout=10).text
license_text_zh = requests.get(license_url_zh, timeout=10).text
eula_text = requests.get(eula_url, timeout=10, proxies=proxies).text
license_text = requests.get(license_url, timeout=10, proxies=proxies).text
license_text_zh = requests.get(license_url_zh, timeout=10, proxies=proxies).text
except Exception:
print("获取最终用户许可协议失败,请检查网络连接")
input("按Enter键继续...\n")
Expand Down
8 changes: 6 additions & 2 deletions src/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
from colorama import Fore, Style, init

init(autoreset=True)
proxies = {
"http": None,
"https": None
}


# 替换非法字符
Expand Down Expand Up @@ -75,7 +79,7 @@ def get_fanqie(url, user_agent):

# 获取网页源码

response = requests.get(url, headers=headers, timeout=20)
response = requests.get(url, headers=headers, timeout=20, proxies=proxies)
html = response.text

# 解析网页源码
Expand Down Expand Up @@ -133,7 +137,7 @@ def get_api(chapter, headers):
while retry_count < 4: # 设置最大重试次数
try:
# 获取 api 响应
api_response = requests.get(api_url, headers=headers, timeout=5)
api_response = requests.get(api_url, headers=headers, timeout=5, proxies=proxies)

# 解析 api 响应为 json 数据
api_data = api_response.json()
Expand Down

0 comments on commit a046595

Please sign in to comment.