I have a list of dictionaries containing data on products. Each product has one image URL. The data looks very much like below:
products_dicts = [
{
"uniq_id": "123987",
"sku": "123",
"name": "ABC",
"cat": "DEF",
"cat_tree": "A|B|C",
"image_urls": "http://sitecom/image1.tif"
},
{
"uniq_id": "987123",
"sku": "987",
"name": "GHI",
"cat": "JKL",
"cat_tree": "Z|Y|X",
"image_urls": "http://sitecom/img/image2.tif"
}
]
I want to use the urllib.request()
to retrieve the image and display it for product
with the uniq_id
equals to 123987
. I have started with the following:
import urllib.request
from PIL import Image
q = [x['product_image_urls'] for x in products_dicts if x['uniq_id'] == '123987']