|
5 | 5 | import zipfile |
6 | 6 | import os |
7 | 7 | import sys |
| 8 | +import time |
8 | 9 | import traceback |
9 | 10 | import shutil |
10 | 11 |
|
@@ -41,16 +42,20 @@ def is_ofs_installed(): |
41 | 42 |
|
42 | 43 |
|
43 | 44 | def get_download_urls(): |
44 | | - try: |
45 | | - html_text = requests.get(FUNSCRIPT_GENERATOR_RELEASE_URL).text |
46 | | - download_urls = { version.parse(re.search(r'v[^/]*', x).group().lower().replace("v", "")) : "https://github.com" + x \ |
47 | | - for x in [link.get('href') for link in BeautifulSoup(html_text, 'html.parser').find_all('a') \ |
48 | | - if link.get('href').endswith(".zip") and "/releases/" in link.get('href')] |
49 | | - } |
50 | | - latest = max(download_urls) |
51 | | - return download_urls, latest |
52 | | - except: |
53 | | - error("Download URL not found (" + FUNSCRIPT_GENERATOR_RELEASE_URL + ")") |
| 45 | + # sometimes requests failed to fetch the url so we try up to 3 times |
| 46 | + for i in range(3): |
| 47 | + try: |
| 48 | + html_text = requests.get(FUNSCRIPT_GENERATOR_RELEASE_URL).text |
| 49 | + download_urls = { version.parse(re.search(r'v[^/]*', x).group().lower().replace("v", "")) : "https://github.com" + x \ |
| 50 | + for x in [link.get('href') for link in BeautifulSoup(html_text, 'html.parser').find_all('a') \ |
| 51 | + if link.get('href').endswith(".zip") and "/releases/" in link.get('href')] |
| 52 | + } |
| 53 | + latest = max(download_urls) |
| 54 | + return download_urls, latest |
| 55 | + except: |
| 56 | + time.sleep(2) |
| 57 | + if i == 2: |
| 58 | + error("Download URL not found (" + FUNSCRIPT_GENERATOR_RELEASE_URL + ")") |
54 | 59 |
|
55 | 60 |
|
56 | 61 | def is_latest_version_installed(version_file, version): |
@@ -105,6 +110,7 @@ def update(download_urls, latest): |
105 | 110 | if platform.system() != "Windows": |
106 | 111 | error("This installer only work on Windows") |
107 | 112 |
|
| 113 | + print("Start MTFG installation") |
108 | 114 | is_ofs_installed() |
109 | 115 | download_urls, latest = get_download_urls() |
110 | 116 | update(download_urls, latest) |
|
0 commit comments