Shraddha Gami
Add personalised reco
138c021
import pandas as pd
import json
def read_json(file_name):
with open(file_name) as json_file:
data = json.load(json_file)
return data
catalog_data = read_json('catalog.json')
inst = catalog_data[0]
print("Catalog data")
print(inst)
for key, value in inst.items():
print("Key: ", key)
print("Value: ", value)
print()
for key, value in inst.items():
if key == "medias":
print(value[0]['url'])
if key == 'name':
print(value)
uid_name_map = {}
uid_url_map = {}
for inst in catalog_data:
for key, value in inst.items():
if key == "medias":
uid_url_map[inst['uid']] = value[0]['url']
if key == 'name':
uid_name_map[inst['uid']] = value
print(len(uid_name_map))
print(len(uid_url_map))
with open('uid_name_map.json', 'w') as json_file:
json.dump(uid_name_map, json_file, indent=4)
with open('uid_url_map.json', 'w') as json_file:
json.dump(uid_url_map, json_file, indent=4)
# import pickle
# def save_obj(obj, name):
# with open(name, 'wb') as f:
# pickle.dump(obj, f)
# save_obj(uid_name_map, 'new_uid_name_map.pkl')
# save_obj(uid_url_map, 'new_uid_url_map.pkl')