-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.py
49 lines (40 loc) · 1.46 KB
/
1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import requests
import os
import hashlib
def get_file_info(url):
try:
# 发送 GET 请求获取文件内容
response = requests.get(url)
if response.status_code == 200:
# 获取文件名
filename = url.split('/')[-1]
# 保存文件
with open(filename, 'wb') as f:
f.write(response.content)
# 计算文件大小
file_size = os.path.getsize(filename)
# 计算 SHA1 值
sha1_hash = hashlib.sha1()
with open(filename, 'rb') as f:
# 分块读取文件,适用于大文件
for chunk in iter(lambda: f.read(4096), b""):
sha1_hash.update(chunk)
# 获取链接 ID
id = url.split('/')[-1].replace('.jar', '')
# 输出文件大小和 SHA1 值
print(f"文件大小: {file_size} 字节")
print(f"SHA1 值: {sha1_hash.hexdigest()}")
print(f"ID: {id}")
# 删除文件
os.remove(filename)
print("文件已删除")
else:
print("无法获取文件")
except Exception as e:
print(f"发生异常: {e}")
if __name__ == "__main__":
while True:
url = input("请输入链接 (输入 'exit' 退出程序): ")
if url.lower() == 'exit':
break
get_file_info(url)