File size: 1,203 Bytes
138c021
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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')