-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcliApp.py
More file actions
96 lines (84 loc) · 3.27 KB
/
cliApp.py
File metadata and controls
96 lines (84 loc) · 3.27 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import requests
BASE_URL = "http://localhost:8000"
def create_item():
name = input("Enter the name of the item: ")
response = requests.post(f"{BASE_URL}/items/", json={"name": name})
if response.status_code == 200:
print(f"Item created with ID: {response.json()['item_id']}")
else:
print(f"Error: {response.text}")
def modify_item():
item_id = input("Enter the ID of the item to modify: ")
new_name = input("Enter the new name of the item: ")
response = requests.put(f"{BASE_URL}/items/", json={"item_id": item_id, "new_name": new_name})
if response.status_code == 200:
print(f"Item with ID {item_id} modified.")
else:
print(f"Error: {response.text}")
def get_items():
response = requests.get(f"{BASE_URL}/items/")
if response.status_code == 200:
print("Items:", response.json()["items"])
else:
print(f"Error: {response.text}")
def get_modification_count():
item_id = input("Enter the ID of the item: ")
response = requests.get(f"{BASE_URL}/analytics/{item_id}/modification_count")
if response.status_code == 200:
print(f"Modification count for item {item_id}: {response.json()['modification_count']}")
else:
print(f"Error: {response.text}")
def get_modification_history():
item_id = input("Enter the ID of the item: ")
response = requests.get(f"{BASE_URL}/analytics/{item_id}/modification_history")
if response.status_code == 200:
print(f"Modification history for item {item_id}: {response.json()['modification_history']}")
else:
print(f"Error: {response.text}")
def get_item_history():
item_id = input("Enter the ID of the item: ")
response = requests.get(f"{BASE_URL}/history/{item_id}")
if response.status_code == 200:
print(f"History for item {item_id}: {response.json()['history']}")
else:
print(f"Error: {response.text}")
def compare_histories():
item_id = input("Enter the ID of the item: ")
response = requests.get(f"{BASE_URL}/history/{item_id}/comparison")
if response.status_code == 200:
print(f"Comparison of histories for item {item_id}: {response.json()['comparison']}")
else:
print(f"Error: {response.text}")
def main():
while True:
print("\nChoose an option:")
print("1. Create a new item")
print("2. Modify an existing item")
print("3. Get all items")
print("4. Get modification count of an item")
print("5. Get modification history of an item")
print("6. Get history of an item")
print("7. Compare histories of an item")
print("8. Exit")
choice = input("Enter the number of your choice: ")
if choice == "1":
create_item()
elif choice == "2":
modify_item()
elif choice == "3":
get_items()
elif choice == "4":
get_modification_count()
elif choice == "5":
get_modification_history()
elif choice == "6":
get_item_history()
elif choice == "7":
compare_histories()
elif choice == "8":
print("Exiting the CLI.")
break
else:
print("Invalid choice. Please enter a number between 1 and 8.")
if __name__ == "__main__":
main()