Skip to content

Commit 6fca9ba

Browse files
author
arch
committed
add windows installer template
1 parent 9a19694 commit 6fca9ba

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

contrib/windows_installer.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import urllib.request
2+
import requests
3+
import re
4+
import platform
5+
import zipfile
6+
import os
7+
8+
from packaging import version
9+
from bs4 import BeautifulSoup # beautifulsoup4
10+
from tqdm import tqdm
11+
12+
13+
class DownloadProgressBar(tqdm):
14+
def update_to(self, b=1, bsize=1, tsize=None):
15+
if tsize is not None:
16+
self.total = tsize
17+
self.update(b * bsize - self.n)
18+
19+
20+
def download_url(url, output_path):
21+
with DownloadProgressBar(unit='B', unit_scale=True,
22+
miniters=1, desc=url.split('/')[-1]) as t:
23+
urllib.request.urlretrieve(url, filename=output_path, reporthook=t.update_to)
24+
25+
26+
release_url = "https://github.com/michael-mueller-git/Python-Funscript-Editor/releases"
27+
html_text = requests.get(release_url).text
28+
download_urls = { version.parse(re.search(r'v[^/]*', x).group().lower().replace("v", "")) : "https://github.com" + x \
29+
for x in [link.get('href') for link in BeautifulSoup(html_text, 'html.parser').find_all('a') \
30+
if link.get('href').endswith(".zip") and "/releases/" in link.get('href')]
31+
}
32+
latest = max(download_urls)
33+
zip_file = "funscript-editor-v" + str(latest) + ".zip"
34+
35+
if not os.path.exists(zip_file):
36+
download_url(download_urls[latest], zip_file)
37+
38+
with zipfile.ZipFile(zip_file) as zf:
39+
for member in tqdm(zf.infolist(), desc='Extracting '):
40+
zf.extract(member, "funscript-editor")

0 commit comments

Comments
 (0)