-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpb_setup.py
More file actions
50 lines (41 loc) · 1.54 KB
/
Copy pathpb_setup.py
File metadata and controls
50 lines (41 loc) · 1.54 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import asyncio
import json
import httpx
async def setup():
async with httpx.AsyncClient() as client:
try:
r1 = await client.post(
"http://127.0.0.1:8090/api/admins",
json={
"email": "admin@test.com",
"password": "adminpassword123",
"passwordConfirm": "adminpassword123",
},
)
print("Admin created:", r1.status_code)
except Exception:
pass
r2 = await client.post(
"http://127.0.0.1:8090/api/admins/auth-with-password",
json={"identity": "admin@test.com", "password": "adminpassword123"},
)
token = r2.json().get("token")
print("Logged in, token:", token[:10])
with open("pocketbase_schema.json", encoding="utf-8") as f:
collections = json.load(f)
r3 = await client.put(
"http://127.0.0.1:8090/api/collections/import",
json={"collections": collections, "deleteMissing": False},
headers={"Authorization": f"Bearer {token}"},
)
print("Imported collections:", r3.status_code, r3.text)
r4 = await client.post(
"http://127.0.0.1:8090/api/collections/fricciones/records",
json={
"description": "Odio configurar servidores web manualmente, pierdo horas.",
"severity": 4,
},
)
print("Inserted friction:", r4.status_code)
if __name__ == "__main__":
asyncio.run(setup())