60 lines
1.3 KiB
Python
60 lines
1.3 KiB
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
from datetime import date
|
||
|
|
||
|
import requests
|
||
|
|
||
|
BASE = "https://in.ccc.ac"
|
||
|
|
||
|
|
||
|
session = requests.Session()
|
||
|
# session.auth = (":)", ":)")
|
||
|
|
||
|
res = session.get(f"{BASE}/api/items")
|
||
|
res.raise_for_status()
|
||
|
items = res.json()
|
||
|
|
||
|
is_in = input("is in (eg. R7): ")
|
||
|
print(items[is_in])
|
||
|
|
||
|
|
||
|
def format_last_updated(item) -> str:
|
||
|
last_updated = item["last_updated"]
|
||
|
if last_updated is None:
|
||
|
return ""
|
||
|
return date.fromtimestamp(item["last_updated"]).isoformat()[:-3]
|
||
|
|
||
|
|
||
|
print(f"Items that should be in {is_in}:")
|
||
|
print(
|
||
|
"\n".join(
|
||
|
(
|
||
|
f"{item['id']:<5} last_updated={format_last_updated(item)}"
|
||
|
for item in items.values()
|
||
|
if item["is_in"] == is_in
|
||
|
)
|
||
|
)
|
||
|
)
|
||
|
|
||
|
while True:
|
||
|
try:
|
||
|
item_id = input(f"item that is in {is_in}: ")
|
||
|
except KeyboardInterrupt:
|
||
|
break
|
||
|
if item_id == "":
|
||
|
break
|
||
|
|
||
|
if item_id not in items:
|
||
|
item_id = "K" + str(int(item_id))
|
||
|
if item_id not in items:
|
||
|
print(f"{item_id} and K{item_id} do not exist.")
|
||
|
continue
|
||
|
item = items[item_id]
|
||
|
|
||
|
print(f'location of {item_id}: {item["is_in"]} ->', end="")
|
||
|
item["is_in"] = is_in
|
||
|
print(f' {item["is_in"]}')
|
||
|
|
||
|
res = session.put(f"{BASE}/api/items/{item_id}", json=item)
|
||
|
res.raise_for_status()
|