Skip to content

Commit a276aa6

Browse files
Merge pull request #85 from AdaGold/ks_update_cli
Update CLI for AirPlay & changed endpoint responses
2 parents 70248ce + 6af173e commit a276aa6

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

cli/main.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"10": "Quit"
1414
}
1515

16-
def list_options():
1716

17+
def list_options():
1818
for number, feature in OPTIONS.items():
1919
print(f"{number}. {feature}")
2020

@@ -29,14 +29,15 @@ def make_choice():
2929

3030
return choice
3131

32+
3233
def get_task_from_user(msg = "Input the id of the task you would like to work with: "):
3334
task = None
3435
tasks = task_list.list_tasks()
3536
if not tasks:
3637
task_list.print_stars("This option is not possible because there are no tasks.")
3738
return task
3839
count = 0
39-
help_count = 3 #number of tries before offering assistance
40+
help_count = 3 # number of tries before offering assistance
4041
while not task:
4142
id = input(msg)
4243
task = task_list.get_task(id)
@@ -49,6 +50,7 @@ def get_task_from_user(msg = "Input the id of the task you would like to work wi
4950

5051
return task
5152

53+
5254
def print_task(task):
5355
print_single_row_of_stars()
5456
print("title: ", task["title"])
@@ -57,45 +59,56 @@ def print_task(task):
5759
print("id: ", task["id"])
5860
print_single_row_of_stars()
5961

62+
6063
def print_all_tasks():
6164
tasks = task_list.list_tasks()
65+
6266
print("\nTasks:")
6367
if not tasks:
6468
print_surround_stars("No tasks")
6569
else:
6670
for task in tasks:
6771
print_task(task)
72+
6873
print_single_row_of_stars()
6974

75+
7076
def print_surround_stars(sentence):
7177
print_single_row_of_stars()
7278
print(sentence)
7379
print_single_row_of_stars()
7480

81+
7582
def print_single_row_of_stars():
7683
print("\n**************************\n")
7784

85+
7886
def create_task():
7987
print("Great! Let's create a new task.")
8088
title=input("What is the title of your task? ")
8189
description=input("What is the description of your task? ")
8290
response = task_list.create_task(title, description)
8391
print_task(response)
8492

93+
8594
def view_task():
8695
task = get_task_from_user("Input the id of the task you would like to select ")
8796
if task:
8897
print("\nSelected Task:")
8998
print_task(task)
9099

100+
91101
def edit_task():
92102
task = get_task_from_user()
93103
if task:
94104
title=input("What is the new title of your task? ")
95105
description=input("What is the new description of your task? ")
96-
response = task_list.update_task(task["id"], title, description)
106+
task_list.update_task(task["id"], title, description)
107+
97108
print("\nUpdated Task:")
98-
print_task(response)
109+
updated_task = task_list.get_task(task["id"])
110+
print_task(updated_task)
111+
99112

100113
def delete_task_ui():
101114
task = get_task_from_user("Input the id of the task you would like to delete: ")
@@ -104,26 +117,30 @@ def delete_task_ui():
104117
print("\nTask has been deleted.")
105118
print_all_tasks()
106119

120+
107121
def change_task_complete_status(status):
108122
status_text = "complete"
109123
if not status:
110124
status_text = "incomplete"
111125
task = get_task_from_user(f"Input the id of the task you would like to mark {status_text}: ")
112126
if task:
113127
if status:
114-
response = task_list.mark_complete(task["id"])
128+
task_list.mark_complete(task["id"])
115129
else:
116-
response = task_list.mark_incomplete(task["id"])
130+
task_list.mark_incomplete(task["id"])
131+
117132
print(f"\nTask marked {status_text}:")
118-
print_task(response)
133+
updated_task = task_list.get_task(task["id"])
134+
print_task(updated_task)
135+
119136

120137
def delete_all_tasks():
121138
for task in task_list.list_tasks():
122139
task_list.delete_task(task["id"])
123140
print_surround_stars("Deleted all tasks.")
124141

142+
125143
def run_cli():
126-
127144
play = True
128145
while play:
129146

cli/task_list.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import requests
22

3-
url = "http://localhost:5000"
3+
url = "http://127.0.0.1:5000"
44

5-
def parse_response(response):
5+
def parse_task_from_response(response):
66
if response.status_code >= 400:
77
return None
88

@@ -15,18 +15,21 @@ def create_task(title, description, completed_at=None):
1515
"completed_at": completed_at
1616
}
1717
response = requests.post(url+"/tasks",json=query_params)
18-
return parse_response(response)
18+
return parse_task_from_response(response)
19+
1920

2021
def list_tasks():
2122
response = requests.get(url+"/tasks")
2223
return response.json()
2324

25+
2426
def get_task(id):
2527
response = requests.get(url+f"/tasks/{id}")
2628
if response.status_code != 200:
2729
return None
2830

29-
return parse_response(response)
31+
return parse_task_from_response(response)
32+
3033

3134
def update_task(id,title,description):
3235

@@ -40,20 +43,20 @@ def update_task(id,title,description):
4043
json=query_params
4144
)
4245

43-
return parse_response(response)
46+
return response
47+
4448

4549
def delete_task(id):
4650
response = requests.delete(url+f"/tasks/{id}")
47-
return response.json()
51+
return response
52+
4853

4954
def mark_complete(id):
5055
response = requests.patch(url+f"/tasks/{id}/mark_complete")
51-
return parse_response(response)
56+
return response
57+
5258

5359
def mark_incomplete(id):
5460
response = requests.patch(url+f"/tasks/{id}/mark_incomplete")
55-
return parse_response(response)
56-
61+
return response
5762

58-
59-

0 commit comments

Comments
 (0)