-
Notifications
You must be signed in to change notification settings - Fork 12
/
list_kenwood_updates.py
70 lines (54 loc) · 1.99 KB
/
list_kenwood_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
#!/usr/bin/env python3
import requests
import re
BASE_URL = "https://kenwood.garmin.com"
MAIN_URL = "/kenwood/site/filterHeadUnitList"
reqs = requests.Session()
def get_url(url, params = {}, outfile = None):
global reqs
print("Now fetching {} ...".format(url))
#print(repr(params))
req = reqs.get(url, params=params)
page = req.content
#if outfile:
# with open(outfile, "wb") as f:
# f.write(page)
page = str(page).replace("\\n", "").replace("\\r", "").replace("\\t", "")
page = re.sub(r"\s+", " ", page)
return page
devlist = get_url(BASE_URL + MAIN_URL, {"regionKey": 0, "seriesKey": 0}, "kenmain.html")
devices = re.findall(r"<div class=\"item\"> <a href=\"(.*?)\">(.*?)</a> </div>", devlist)
print("Found {} devices.".format(len(devices)))
#print(repr(devices))
f = open("kenfiles.txt", "wt")
f.write("# Download with: wget -x -nc -i kenfiles.txt\n\n")
for dev in devices:
(url, devname) = dev
print("Checking updates for {} ...".format(devname.strip()))
url = url.strip()
(url, paramstr) = url.split("?", 1)
parampairs = paramstr.split("&")
params = {}
for p in parampairs:
(key, val) = p.split("=", 1)
params[key] = val
params["origin"] = "productUpdate" # gets added via JavaScript?
devpage = get_url(BASE_URL + url, params, "kendev.html")
updateLink = re.search(r"(/kenwood/site/softwareUpdates.*?)\\", devpage)
if not updateLink:
print("### No updates for {} found.".format(devname))
continue
updateLink = updateLink.group(1)
#print(repr(updateLink))
updpage = get_url(BASE_URL + updateLink, {}, "kenupd.html")
#print(repr(updpage))
links = re.findall(r"(https?://.*?)[\\\"']", updpage)
f.write("# {}\n".format(devname))
for l in links:
if l.endswith(("favicon.ico", "garmin.png", "termsOfUse.htm", "privacy-statement", "/us/")):
continue
#print(repr(l))
f.write(l)
f.write("\n")
f.write("\n")
f.close()