Skip to content

Commit

Permalink
fix: 修复更新问题
Browse files Browse the repository at this point in the history
  • Loading branch information
shing-yu committed Nov 22, 2023
1 parent 588a0fb commit 6f2a9a5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import function as f
from sys import exit

version = "v2.8.2"
version = "v2.8.3"

# 检查更新
f.check_update(version)
Expand Down
54 changes: 38 additions & 16 deletions src/qimao_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,16 @@ def qimao_update(data_folder):
print(f"{novel_name} 已是最新,不需要更新。\n")
else:
print(f"{novel_name} 已更新完成。\n")
# 计算文件 sha256 值
hash_sha256 = hashlib.sha256()
with open(txt_file_path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_sha256.update(chunk)
sha256_hash = hash_sha256.hexdigest()
# 获取当前系统时间
current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# 创建要写入元信息文件的内容
new_content = f"{current_time}\n{url}\n{result}\n{encoding}"
new_content = f"{current_time}\n{url}\n{result}\n{encoding}\n{sha256_hash}"
# 打开文件并完全覆盖内容
with open(upd_file_path, "w") as file:
file.write(new_content)
Expand Down Expand Up @@ -282,36 +288,52 @@ def onefile(data_folder):
url = lines[1].strip()
last_chapter_id = lines[2].strip()
encoding = lines[3].strip()
save_sha256 = lines[4].strip()
if len(lines) >= 5:
save_sha256 = lines[4].strip()
skip_hash = 0
else:
print(Fore.YELLOW + Style.BRIGHT + "此小说可能由老版本下载,跳过hash校验")
save_sha256 = None
skip_hash = 1
hash_sha256 = hashlib.sha256()
with open(txt_file_path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_sha256.update(chunk)
fact_sha256 = hash_sha256.hexdigest()

if fact_sha256 != save_sha256:
print(Fore.RED + Style.BRIGHT + "hash校验未通过!")
while True:
upd_choice = input(f"这往往意味着文件已被修改,是否继续更新?(yes/no):")
if upd_choice == "yes":
break
elif upd_choice == "no":
print(Fore.RED + Style.BRIGHT + "更新已取消")
if skip_hash == 0:
if fact_sha256 != save_sha256:
print(Fore.RED + Style.BRIGHT + "hash校验未通过!")
while True:
upd_choice = input(f"这往往意味着文件已被修改,是否继续更新?(yes/no):")
if upd_choice == "yes":
skip_this = 0
break
elif upd_choice == "no":
skip_this = 1
break
else:
print("输入错误,请重新输入")
if skip_this == 1:
print(Fore.RED + Style.BRIGHT + f"《{novel_name}》的更新已取消")
return
else:
print("输入错误,请重新输入")
else:
print(Fore.GREEN + Style.BRIGHT + "hash校验通过!")
else:
print(Fore.GREEN + Style.BRIGHT + "hash校验通过!")
print(f"上次更新时间{last_update_time}")
result = download_novel(url, encoding, last_chapter_id, txt_file_path)
if result == "DN":
print(f"{novel_name} 已是最新,不需要更新。\n")
else:
print(f"{novel_name} 已更新完成。\n")
# 计算文件 sha256 值
hash_sha256 = hashlib.sha256()
with open(txt_file_path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_sha256.update(chunk)
sha256_hash = hash_sha256.hexdigest()
# 获取当前系统时间
current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# 创建要写入元信息文件的内容
new_content = f"{current_time}\n{url}\n{result}\n{encoding}"
new_content = f"{current_time}\n{url}\n{result}\n{encoding}\n{sha256_hash}"
# 打开文件并完全覆盖内容
with open(upd_file_path, "w") as file:
file.write(new_content)
Expand Down

0 comments on commit 6f2a9a5

Please sign in to comment.