mirror of
https://gitlab.aachen.ccc.de/inventory/in.git
synced 2024-11-25 16:53:59 +01:00
add client-side python script to create items in bulk
This commit is contained in:
parent
ea0538f90c
commit
8f5a82fb41
1 changed files with 47 additions and 0 deletions
47
contrib/bulk_create.py
Executable file
47
contrib/bulk_create.py
Executable file
|
@ -0,0 +1,47 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
BASE = "https://in.ccc.ac/api"
|
||||||
|
COUNT = 0
|
||||||
|
START_ID = 1
|
||||||
|
|
||||||
|
|
||||||
|
session = requests.Session()
|
||||||
|
# session.auth = (":)", ":)")
|
||||||
|
|
||||||
|
res = session.get(f"{BASE}/items")
|
||||||
|
res.raise_for_status()
|
||||||
|
ids = res.json().keys()
|
||||||
|
kiste_ids = {int(i.lstrip("K")) for i in ids if i.startswith("K") and i != "K"}
|
||||||
|
print("existing ids:", repr(kiste_ids), file=sys.stderr)
|
||||||
|
|
||||||
|
current_id = START_ID
|
||||||
|
new_ids = []
|
||||||
|
while len(new_ids) < COUNT:
|
||||||
|
if current_id not in kiste_ids:
|
||||||
|
new_ids.append(current_id)
|
||||||
|
current_id += 1
|
||||||
|
|
||||||
|
print("created:", file=sys.stderr)
|
||||||
|
if len(new_ids) == 0:
|
||||||
|
print("(none)", file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
|
for i in new_ids:
|
||||||
|
j = {
|
||||||
|
"id": f"K{i}",
|
||||||
|
"is_in": None,
|
||||||
|
"coords_bl": None,
|
||||||
|
"coords_tr": None,
|
||||||
|
"type": "Kiste",
|
||||||
|
"name": None,
|
||||||
|
"content": None,
|
||||||
|
"note": "Bitte Name, Ort, Inhalt eintragen",
|
||||||
|
"hidden": False,
|
||||||
|
}
|
||||||
|
res = session.put(f"{BASE}/items/{j['id']}", json=j)
|
||||||
|
res.raise_for_status()
|
||||||
|
print(f"{j['id']},https://in.ccc.ac/form.html?id={j['id']}")
|
Loading…
Reference in a new issue