-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed_postgres.py
More file actions
32 lines (30 loc) · 1.33 KB
/
seed_postgres.py
File metadata and controls
32 lines (30 loc) · 1.33 KB
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
import urllib.request
import json
products = [
{"name": "iPad", "price": 200000, "stock": 4},
{"name": "Keyboard", "price": 4000, "stock": 4},
{"name": "Ram", "price": 12000, "stock": 2},
{"name": "SSD", "price": 16000, "stock": 5},
{"name": "Iphone", "price": 120000, "stock": 5},
{"name": "Samsung TV", "price": 50000, "stock": 10},
{"name": "Laptop", "price": 90000, "stock": 10},
{"name": "Headphone", "price": 8000, "stock": 10},
{"name": "Washing Machine","price": 80000, "stock": 8},
{"name": "PS5", "price": 70000, "stock": 10},
{"name": "Mystery Box", "price": 500, "stock": 5},
{"name": "Earbud", "price": 5000, "stock": 7},
{"name": "Smart Watch", "price": 7000, "stock": 2},
{"name": "Mouse", "price": 3000, "stock": 8},
{"name": "LED Monitor", "price": 60000, "stock": 3},
]
for p in products:
data = json.dumps(p).encode("utf-8")
req = urllib.request.Request(
"http://localhost:8000/products/",
data=data,
headers={"Content-Type": "application/json"},
method="POST"
)
with urllib.request.urlopen(req) as resp:
result = json.loads(resp.read())
print(f"Created: {result['name']} (id={result['id']})")