-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_strategy_blacklist.py
executable file
·78 lines (66 loc) · 2.54 KB
/
update_strategy_blacklist.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
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
78
#!/usr/bin/env python3
# AutoUpdateNFIX2 : Strategy + Blacklist
# Author : crashzanders
# Version : 1.3
import requests, re, subprocess
from datetime import datetime
from config import url, url_blacklist, file, file_blacklist, command, bot_token, chat_id
change = False
def check_version_online(url):
file_path = url
content = requests.get(file_path).text
pattern = r"v\d+\.\d+\.\d+"
match = re.search(pattern, content)
version_online = match.group(0)
print("Online version of the strategy : " +version_online)
return version_online
def check_version_file(file):
with open(file, "r") as file:
content = file.read()
pattern = r"v\d+\.\d+\.\d+"
match = re.search(pattern, content)
version = match.group(0)
print("Local strategy version : " +version)
return version
def update_file(url, file):
response = requests.get(url)
file_path = file
with open(file_path, "w", encoding="utf-8") as f:
f.write(response.text)
def send_notification(bot_token, chat_id, message):
url_telegram = f"https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={message}"
requests.get(url_telegram).json()
print("--- LAUNCHING THE STRATEGY UPDATE SCRIPT ---")
current_time = datetime.now().strftime("%Y/%m/%d - %H:%M")
print("--- "+current_time+" ---")
# Check and upgrade strategy file
version_online = str(check_version_online(url))
version_file= str(check_version_file(file))
if version_file != version_online:
print("New strategy version detected: Update")
send_notification(bot_token, chat_id, "New version of NostalgiaForInfinityX2 strategy detected. Upgrade in progress...")
update_file(url, file)
print("Updated strategy")
change = True
else:
print("Strategy : Updated version")
#Check and upgrade blacklist file
response = requests.get(url_blacklist)
remote_content = response.content.decode('utf-8')
with open(file_blacklist, 'r') as f:
local_content = f.read()
if remote_content != local_content:
print("New blacklist version detected: Update")
send_notification(bot_token, chat_id, "New version of blacklist detected. Upgrade in progress...")
with open(file_blacklist, 'w') as f:
f.write(remote_content)
print("Updated blacklist")
change = True
else:
print("Blacklist : Updated version")
#Restart process
if change == True:
send_notification(bot_token, chat_id, "Upgrade completed. Restart services...")
subprocess.run(command, shell=True)
print("Restarted services")
print("--- END OF THE STRATEGY UPDATE SCRIPT ---\n")