-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_hash.py
More file actions
62 lines (52 loc) · 2.1 KB
/
Copy pathcheck_hash.py
File metadata and controls
62 lines (52 loc) · 2.1 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
# @Time : 2021/03/23
# @Author : Naunter
# @Page : https://github.com/Naunter
# @Page : https://github.com/Naunter/bdocn_client_en
from hashlib import sha256
from urllib.request import build_opener,install_opener,urlopen
from socket import timeout
from tkinter.messagebox import showinfo
from time_template import time_template
user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0'
def get_online_hash(url):
time_template()
print("check_hash.py >>> def get_online_hash()")
print("check_hash.py >>> def get_online_hash(): url: " + str(url))
opener = build_opener()
opener.addheaders = [('User-agent', user_agent)]
install_opener(opener)
try:
a = urlopen(url, timeout=10)
except:
print("check_hash.py >>> def get_online_hash(url): something wrong, maybe timeout")
showinfo('get_online_hash','Get online hash timeout,please retry!')
online_hash = False
else:
online_hash = a.read().decode('utf-8').strip()
print("check_hash.py >>> def get_online_hash(): online_hash: " + str(online_hash))
return online_hash
def get_local_hash(path):
time_template()
print("check_hash.py >>> def get_local_hash()")
print("check_hash.py >>> def get_local_hash(): path: " + str(path))
BUF_SIZE = 65536
hash_sha256 = sha256()
with open(path, 'rb') as f:
while True:
data = f.read(BUF_SIZE)
if not data:
break
else:
hash_sha256.update(data)
print("check_hash.py >>> def get_local_hash(): hash_sha256.hexdigest(): " + format(hash_sha256.hexdigest()))
return(format(hash_sha256.hexdigest()))
def get_github_loc_en_sea_hash():
time_template()
print("check_hash.py >>> def get_github_loc_en_sea_hash()")
url = 'https://github.com/BDO-CnHope/bdocn/raw/master/CHECK/LOC_EN_SEA_SHA256'
if get_online_hash(url) != False:
a_hash = get_online_hash(url)
print("check_hash.py >>> def get_github_loc_en_sea_hash(): a_hash: "+str(a_hash))
else:
a_hash = False
return a_hash