-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsamsung-updates.py
executable file
·135 lines (122 loc) · 4.37 KB
/
samsung-updates.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/python3 -u
from copy import deepcopy
import json
import requests
import time
import urllib.request
import xml.etree.ElementTree as ET
with open("token.txt", "r") as file:
token = file.read().rstrip("\n")
# Models to check
models = {
# Galaxy S24
"SM-S9210": ["BRI", "CHC"],
"SC-51E": ["DCM"],
"SCG25": ["KDI"],
"SM-S921Q": ["SJP"],
"SM-S921U": ["ATT"],
"SM-S921U1": ["ATT"],
"SM-S921W": ["BMC"],
# Galaxy S24+
"SM-S9260": ["BRI", "CHC"],
"SM-S926U": ["ATT"],
"SM-S926U1": ["ATT"],
"SM-S926W": ["BMC"],
# Galaxy S24 Ultra
"SM-S9280": ["BRI", "CHC"],
"SM-S928B": ["EUX"],
"SC-52E": ["DCM"],
"SCG26": ["KDI"],
"SM-S928N": ["KOO"],
"SM-S928Q": ["SJP"],
"SM-S928U": ["ATT"],
"SM-S928U1": ["ATT"],
"SM-S928W": ["BMC"],
# Galaxy Z Flip6
"SM-F7410": ["BRI", "CHC"],
"SM-F741B": ["EUX"],
"SC-54E": ["DCM"],
"SCG29": ["KDI"],
"SM-F741N": ["KOO"],
"SM-F741Q": ["SJP"],
"SM-F741U": ["ATT"],
"SM-F741U1": ["ATT"],
"SM-F741W": ["BMC"],
"SM-W7025": ["CHC"],
# Galaxy Z Fold6
"SM-F9560": ["BRI", "CHC"],
"SM-F956B": ["EUX"],
"SC-55E": ["DCM"],
"SCG28": ["KDI"],
"SM-F956N": ["KOO"],
"SM-F956Q": ["SJP"],
"SM-F956U": ["ATT"],
"SM-F956U1": ["ATT"],
"SM-F956W": ["BMC"],
# Galaxy Z Fold Special Edition
"SM-F958N": ["KOO"],
"SM-W9025": ["CHC"],
}
# JSON file with known updates
try:
with open("samsung-versions.json") as jsonfile:
try:
updates = json.load(jsonfile)
except:
error("Unable to read samsung-versions.json")
except:
updates = {}
warning("File samsung-version.json not found")
def info(text): print(f"\033[94mINFO: \033[00m{text}")
def warning(text): print(f"\033[93mWARNING: \033[00m{text}")
def error(text): print(f"\033[91mERROR: \033[00m{text}")
def sendmessage(text):
url = f"https://api.telegram.org/bot{token}/sendmessage"
params = {"chat_id": "@samsung_sm8650_updates", "parse_mode": "HTML", "text": text}
requests.post(url, params)
while True:
diff_updates = deepcopy(updates)
for model, csc_list in models.items():
for csc in csc_list:
url = f"https://fota-cloud-dn.ospserver.net/firmware/{csc}/{model}/version.xml"
try:
response = urllib.request.urlopen(url).read()
except:
warning(f"Unable to connect to {url}")
time.sleep(60)
continue
tree = ET.fromstring(response)
for version in tree.iter("latest"):
if version.text == None:
warning(f"No updates found for {model} ({csc})")
time.sleep(5)
break
if updates.get(model, None) == None:
updates[model] = {}
fwver = version.text.split("/")
osver = version.attrib["o"]
info(f"{fwver[0]}: Got version from API")
try:
if updates[model][csc] != None:
for key, val in updates[model].items():
if key == csc:
if val == [fwver[0], fwver[1], osver]:
info(f"{fwver[0]}: Already discovered. Skipping")
time.sleep(5)
else:
break
else:
break
except KeyError:
pass
print(f"New update found!\nModel: {model}\nAP: {fwver[0]}\nCSC: {fwver[1]} ({csc})\nAndroid version: {osver}\n")
sendmessage(f"<b>New update found!\nModel:</b> <code>{model}</code>\n<b>AP:</b> <code>{fwver[0]}</code>\n<b>CSC:</b> <code>{fwver[1]}</code> (<code>{csc}</code>)\n<b>Android version:</b> <code>{osver}</code>")
updates[model].update({csc: [fwver[0], fwver[1], osver]})
if diff_updates != updates:
info("Updating samsung-versions.json")
with open("samsung-versions.json", "w") as jsonfile:
json.dump(updates, jsonfile, ensure_ascii=False, indent=4)
# Let's not overwhelm the APIs
time.sleep(5)
info("API scraping finished. Trying again in 20 minutes")
time.sleep(1200)