-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_strategy.py
executable file
·63 lines (52 loc) · 1.96 KB
/
update_strategy.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
#!/usr/bin/env python3
# AutoUpdateNFIX2 : Strategy
# Author : crashzanders
# Version : 1.3
import requests, re, subprocess
from datetime import datetime
from config import url, file, 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")
#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")