forked from dmmbungao/ddos-cua-bao-ngu
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate.py
More file actions
77 lines (62 loc) · 3.15 KB
/
update.py
File metadata and controls
77 lines (62 loc) · 3.15 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 os
import requests
import json
import shutil
import zipfile
from packaging import version
def get_local_version():
try:
with open('version.json', 'r') as file:
data = json.load(file)
return data.get('version')
except FileNotFoundError:
return None
def update_local_version(new_version):
data = {'version': new_version}
with open('version.json', 'w') as file:
json.dump(data, file, indent=2)
def get_github_version():
response = requests.get('https://raw.githubusercontent.com/D4XG/terrorist/main/Tsetting/version.json')
if response.status_code == 200:
return response.json().get('version')
else:
print(f"\x1b[38;5;160m[ \x1b[38;5;255m! \x1b[38;5;160m] \x1b[38;5;255m| \x1b[38;5;160mFailed to fetch the GitHub version. Status code: \x1b[38;5;255m{response.status_code}")
return None
def update_repository():
# Get the latest version from GitHub
github_version = get_github_version()
if github_version:
# Get the current version of the script
local_version = get_local_version()
# Check if an update is needed
if not local_version or version.parse(github_version) > version.parse(local_version):
print("\x1b[38;5;160m[ \x1b[38;5;255m# \x1b[38;5;160m] \x1b[38;5;160m| \x1b[38;5;255mUpdating script...")
# Download the zip file of the repository
download_url = 'https://github.com/D4XG/terrorist/archive/main.zip'
response = requests.get(download_url)
if response.status_code == 200:
# Save the downloaded content to a temporary file
with open('update_temp.zip', 'wb') as temp_file:
temp_file.write(response.content)
# Extract the contents to a temporary folder
with zipfile.ZipFile('update_temp.zip', 'r') as zip_ref:
zip_ref.extractall('update_temp')
# Move the contents from the temporary folder to the main folder
for item in os.listdir('update_temp/terrorist-main'):
source = os.path.join('update_temp/terrorist-main', item)
destination = os.path.join('.', item)
shutil.move(source, destination)
# Cleanup temporary files and folder
os.remove('update_temp.zip')
shutil.rmtree('update_temp')
# Update the local version file
update_local_version(github_version)
print("\x1b[38;5;160m[ \x1b[38;5;255m! \x1b[38;5;160m] \x1b[38;5;160m| \x1b[38;5;255mTerrorist PANEL updated successfully.")
else:
print(f"\x1b[38;5;160m[ \x1b[38;5;255m* \x1b[38;5;160m] \x1b[38;5;160m| Failed to download the update. Status code: \x1b[38;5;255m{response.status_code}")
else:
print("\x1b[38;5;160m[ \x1b[38;5;255m! \x1b[38;5;160m] \x1b[38;5;160m| \x1b[38;5;255mTerrorist is already up-to-date.")
else:
print("\x1b[38;5;160m[ \x1b[38;5;255m! \x1b[38;5;160m] \x1b[38;5;160m| \x1b[38;5;255mFailed to check for updates.")
if __name__ == '__main__':
update_repository()