forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ikea-ota-download.py
41 lines (29 loc) · 782 Bytes
/
ikea-ota-download.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
#!/usr/bin/env python
"""
Snipped to download current IKEA ZLL OTA files into ~/otau
compatible with python 3.
"""
import os
import json
try:
from urllib.request import urlopen, urlretrieve
except ImportError:
from urllib2 import urlopen
from urllib import urlretrieve
f = urlopen("http://fw.ota.homesmart.ikea.net/feed/version_info.json")
data = f.read()
arr = json.loads(data.decode('utf-8'))
otapath = '%s/otau' % os.path.expanduser('~')
if not os.path.exists(otapath):
os.makedirs(otapath)
for i in arr:
if 'fw_binary_url' in i:
url = i['fw_binary_url']
ls = url.split('/')
fname = ls[len(ls) - 1]
path = '%s/%s' % (otapath, fname)
if not os.path.isfile(path):
urlretrieve(url, path)
print(path)
else:
print('%s already exists' % fname)