
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)

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)






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)





Update json.loads line for python 3.5
Update json.loads line for python 3.5

Running the script inside a docker container with python 3.5 throws an "TypeError: the JSON object must be str, not 'bytes'".

Fixed it by decoding downloaded json to utf-8
  
  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)
+ 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)
  
  
  
  
  
Update json.loads line for python 3.5
## Code Before:

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)

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)





## Instruction:
Update json.loads line for python 3.5
## Code After:

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)




