forked from DiscordGSM/DiscordGSM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
46 lines (38 loc) · 1.42 KB
/
update.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
import os
import re
import requests
import shutil
import zipfile
from distutils.dir_util import copy_tree
# get local version
with open('bot.py', 'r') as file:
text = file.read()
local_version = re.findall("VERSION = '(.*?)'", text)
local_version = 'v' + local_version[0]
print(f'Local version:\n{local_version}')
# get remote version
url = 'https://api.github.com/repos/DiscordGSM/DiscordGSM/releases/latest'
r = requests.get(url)
remote_version = re.findall('tag_name":"(.*?)"', r.text)
remote_version = remote_version[0]
print(f'Latest version:\n{remote_version}\n')
if local_version == remote_version:
print(f'DiscordGSM is up to date.')
else:
response = input(f'{remote_version} is available, do you want to update DiscordGSM? [Y/n] ') or 'Y'
if response.upper() == 'Y':
if not os.path.exists("temp"):
os.mkdir('temp')
# download discordgsm
print(f'Download latest DiscordGSM...')
download_url = f'https://github.com/DiscordGSM/DiscordGSM/archive/{remote_version}.zip'
with open('temp/DiscordGSM.zip', 'wb') as file:
r = requests.get(download_url)
file.write(r.content)
# download zip
with zipfile.ZipFile('temp/DiscordGSM.zip', 'r') as zip_ref:
zip_ref.extractall('temp')
# remove zip
os.remove('temp/DiscordGSM.zip')
print(f'Discord updated successfully.')
input("\nPress Enter to continue...")