File size: 1,004 Bytes
4edbe3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import json
import requests

API_URL = "http://localhost:8000/buildings/update_metadata/" 
METADATA_FILE = "./update_metadata.json"

def load_buildings(json_file):
    with open(json_file, "r", encoding="utf-8") as f:
        buildings_list = json.load(f)
        
    return {b["name"]: b for b in buildings_list.values()}

def send_building_data(name, location, height, width, depth):
    data = {
        "name": name,
        "location": location,
        "height": height,
        "width": width,
        "depth": depth
    }

    response = requests.post(API_URL, json=data)

def main():
    buildings = load_buildings(METADATA_FILE)

    for name, building in buildings.items():
        name = building.get("name")
        location = building.get("location")
        height = building.get("height")
        width = building.get("width")
        depth = building.get("depth")
        send_building_data(name, location, height, width, depth)
        
if __name__ == "__main__":
    main()