Repository navigation
Expand file tree
/
Copy pathdownload.py
More file actions
77 lines (61 loc) · 2.04 KB
/
Copy pathdownload.py
File metadata and controls
77 lines (61 loc) · 2.04 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import argparse
import json
import os
import requests
import shutil
import subprocess
def version_tuple(v):
return tuple(map(int, (v.split("."))))
def get_last_version():
result = subprocess.run(
["git", "tag", "--sort=-creatordate"], capture_output=True, text=True
)
version = result.stdout.split("\n")[0].strip()
return version if version else "0.0.0.0"
def check_update():
last_version = get_last_version()
with open("data.json", "r") as f:
data = json.load(f)
latest_version = data["msedge-stable-win-x64"]["version"]
github_env = os.getenv("GITHUB_ENV")
if github_env and os.path.exists(github_env):
with open(github_env, "a") as env_file:
env_file.write(f"latest_version={latest_version}\n")
return version_tuple(last_version) < version_tuple(latest_version)
def get_download_url(version):
with open("data.json", "r") as f:
data = json.load(f)
download_url = data[version]["下载链接"]
return download_url
def get_filename(version):
with open("data.json", "r") as f:
data = json.load(f)
filename = data[version]["文件名"]
return filename
def download_file(url, name):
if os.path.exists(name):
print(f"The file {name} already exists, skip downloading")
return
r = requests.get(url, stream=True)
with open(name, "wb") as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
print("Download complete")
def download():
versions = [
"msedge-stable-win-x86",
"msedge-stable-win-x64",
"msedge-stable-win-ARM64",
]
if check_update():
print("New version detected, start downloading...")
for version in versions:
download_file(get_download_url(version), get_filename(version))
if os.path.exists("__pycache__"):
shutil.rmtree("__pycache__")
else:
print("No new version detected, skip downloading")
return
if __name__ == "__main__":
download()