File tree 20 files changed +194
-12
lines changed
20 files changed +194
-12
lines changed Original file line number Diff line number Diff line change
1
+ import requests
2
+
3
+ # Your code here
Original file line number Diff line number Diff line change
1
+ import requests
2
+
3
+ # Your code here
Original file line number Diff line number Diff line change
1
+ import requests
2
+
3
+ # Your code here
Original file line number Diff line number Diff line change
1
+ import requests
2
+
3
+ # Your code here
Original file line number Diff line number Diff line change
1
+ import requests
2
+
3
+ def get_titles ():
4
+ # Your code here
5
+ return None
6
+
7
+
8
+ print (get_titles ())
Original file line number Diff line number Diff line change
1
+ import requests
2
+
3
+ def get_post_tags (post_id ):
4
+ # Your code here
5
+ return None
6
+
7
+
8
+ print (get_post_tags (146 ))
Original file line number Diff line number Diff line change
1
+ import requests
2
+
3
+ def get_attachment_by_id (attachment_id ):
4
+ # Your code here
5
+ return None
6
+
7
+ print (get_attachment_by_id (137 ))
Original file line number Diff line number Diff line change
1
+ import requests
2
+
3
+ # Your code here
Original file line number Diff line number Diff line change
1
+ import requests
2
+
3
+ response = requests .post ("https://assets.breatheco.de/apis/fake/sample/save-project-json.php" )
4
+ print (response .text )
Original file line number Diff line number Diff line change 1
1
import requests
2
2
3
3
response = requests .get ("https://assets.breatheco.de/apis/fake/sample/time.php" )
4
+
5
+ if response .status_code == 200 :
6
+ timeData = response .json ()
7
+
8
+ hours = timeData ["hours" ]
9
+ minutes = timeData ["minutes" ]
10
+ seconds = timeData ["seconds" ]
11
+
12
+ print (f"Current time: { hours } hrs { minutes } min and { seconds } sec" )
13
+ else :
14
+ print ("Failed to fetch current time." )
15
+
Original file line number Diff line number Diff line change 1
1
import requests
2
2
3
- # Your code here
3
+ # Your code here
4
+
5
+
6
+ response = requests .get ("https://assets.breatheco.de/apis/fake/sample/project1.php" )
7
+
8
+ if response .status_code == 200 :
9
+ Data = response .json ()
10
+
11
+ name = Data ["name" ]
12
+
13
+ print (name )
14
+ else :
15
+ print ("Failed to fetch current time." )
16
+
Original file line number Diff line number Diff line change 1
1
import requests
2
2
3
- # Your code here
3
+ # Your code here
4
+
5
+ response = requests .get ("https://assets.breatheco.de/apis/fake/sample/project_list.php" )
6
+
7
+
8
+ if response .status_code == 200 :
9
+ Data = response .json ()
10
+
11
+ second = Data [1 ]["name" ]
12
+
13
+ print (second )
14
+ else :
15
+ print ("Failed to fetch current time." )
16
+
Original file line number Diff line number Diff line change 1
1
import requests
2
2
3
- # Your code here
3
+ # Your code here
4
+ response = requests .get ("https://assets.breatheco.de/apis/fake/sample/project_list.php" )
5
+
6
+ if response .status_code == 200 :
7
+ # Parsing JSON response
8
+ project_list = response .json ()
9
+
10
+ # Extracting the last project
11
+ last_project = project_list [- 1 ]
12
+
13
+ # Extracting the last image URL
14
+ last_image_url = last_project ["images" ][- 1 ]
15
+
16
+ # Printing the last image URL
17
+ print (last_image_url )
18
+ else :
19
+ print ("Failed to fetch project list." )
Original file line number Diff line number Diff line change 1
1
import requests
2
2
3
3
# Your code here
4
- response = requests .get ("https://assets.breatheco.de/apis/fake/sample/project_list.php " )
4
+ response = requests .get ("https://image.shutterstock.com/image-vector/trophy-cup-award-vector-icon-260nw-592525184.jpg " )
5
5
6
6
if response .status_code == 200 :
7
7
# Parsing JSON response
Original file line number Diff line number Diff line change 1
1
import requests
2
2
3
- # Your code here
3
+ # Your code here
4
+ response = requests .get ("https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php" )
5
+
6
+ if response .status_code == 200 :
7
+ data = response .json ()
8
+
9
+ first_post = data ["posts" ][0 ]
10
+
11
+ author_dict = first_post ["author" ]
12
+
13
+ author_name = author_dict ["name" ]
14
+
15
+ print (author_name )
16
+ else :
17
+ print ("Failed to fetch data from the endpoint." )
Original file line number Diff line number Diff line change 1
1
import requests
2
2
3
3
def get_titles ():
4
- # Your code here
5
- return None
4
+
5
+
6
+ url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"
7
+
8
+ titles = []
9
+
10
+ response = requests .get (url )
11
+
12
+ if response .status_code == 200 :
13
+ data = response .json ()
14
+
15
+ for post in data ["posts" ]:
16
+ title = post ["title" ]
17
+ if title :
18
+ titles .append (title )
19
+ else :
20
+ print ("Error" )
21
+
22
+ return titles
6
23
7
24
8
25
print (get_titles ())
Original file line number Diff line number Diff line change 1
1
import requests
2
2
3
3
def get_post_tags (post_id ):
4
- # Your code here
5
- return None
4
+
5
+
6
+ url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"
7
+
8
+ postTags = []
9
+
10
+ response = requests .get (url )
11
+
12
+ if response .status_code == 200 :
13
+ data = response .json ()
14
+
15
+ for post in data ["posts" ]:
16
+ if post ["id" ] == post_id :
17
+ return post ["tags" ]
18
+ else :
19
+ print ("Error" )
20
+
21
+ return postTags
6
22
7
23
8
24
print (get_post_tags (146 ))
Original file line number Diff line number Diff line change 1
1
import requests
2
2
3
3
def get_attachment_by_id (attachment_id ):
4
- # Your code here
4
+
5
+ url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"
6
+
7
+ postTags = []
8
+ response = requests .get (url )
9
+ if response .status_code == 200 :
10
+
11
+ data = response .json ()
12
+
13
+ for post in data ["posts" ]:
14
+
15
+ if "attachments" in post :
16
+
17
+ for attachment in post ["attachments" ]:
18
+ if attachment ["id" ] == attachment_id :
19
+ return attachment ["title" ]
20
+ else :
21
+ print ("Error" )
22
+
23
+
24
+
25
+
5
26
return None
6
27
7
28
print (get_attachment_by_id (137 ))
Original file line number Diff line number Diff line change 1
1
import requests
2
2
3
- # Your code here
3
+ url = "https://assets.breatheco.de/apis/fake/sample/post.php"
4
+
5
+ response = requests .post (url )
6
+
7
+ print (response .text )
Original file line number Diff line number Diff line change 1
1
import requests
2
2
3
- response = requests .post ("https://assets.breatheco.de/apis/fake/sample/save-project-json.php" )
3
+ url = "https://assets.breatheco.de/apis/fake/sample/save-project-json.php"
4
+
5
+ data = {
6
+ "id" : 2323 ,
7
+ "title" : "Very big project"
8
+ }
9
+
10
+ # Setting the headers
11
+ headers = {
12
+ "Content-Type" : "application/json"
13
+ }
14
+
15
+ # Sending POST request with dictionary data
16
+ response = requests .post (url , json = data , headers = headers )
17
+
4
18
print (response .text )
You can’t perform that action at this time.
0 commit comments