-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest.py
54 lines (47 loc) · 1.81 KB
/
rest.py
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
import requests
import json
def request(url):
resp=requests.get(url)
return resp.json()
url=("https://saral.navgurukul.org/api/courses")
response=requests.get(url)
course=json.loads(response.text)
print(course)
id_list=[]
index=0
while index<len(course["availableCourses"]):
course_id=course["availableCourses"][index]["id"]
course_name=course["availableCourses"][index]["name"]
print(index," ",course_name,course_id)
id_list.append(course_id)
index=index+1
j=int(input('ENTER THE NUMBER ='))
print("index name : ",course["availableCourses"][j]["name"])
a=course["availableCourses"][j]["id"]
print(a)
exercise_json = request("http://saral.navgurukul.org/api/courses/"+a+"/exercises")
slug_list = []
index_1=0
while index_1 < len(exercise_json["data"]):
exercise =exercise_json["data"][index_1]
exercisename=exercise["name"]
print(exercisename)
parent_exercise=exercise["parent_exercise_id"]
index_1=index_1+1
if parent_exercise==None:
exercise_name=exercise["name"]
exercise_slug=exercise["slug"]
slug_list.append(exercise_slug)
print (str(index_1)+ ". " + exercise_name)
elif parent_exercise!=None:
exercise_name=exercise["name"]
exercise_slug=exercise["slug"]
slug_list.append(exercise_slug)
print ("parentexercises",str(index_1)+ ". " + exercise_name)
index_2=0
while index_2<len(exercise["childExercises"]):
child_name=exercise["childExercises"][index_2]["name"]
child_slug=exercise["childExercises"][index_2]["slug"]
slug_list.append(child_slug)
print ("childexercisename: ", str(index_2) + " " + child_name)
index_2=index_2+1