Skip to content

Commit a3f2581

Browse files
committed
repaso
1 parent 8dc90fb commit a3f2581

File tree

7 files changed

+57
-7
lines changed

7 files changed

+57
-7
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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))

.learn/resets/12-post-request/app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import requests
2+
3+
# Your code here
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import requests
2+
3+
response = requests.post("https://assets.breatheco.de/apis/fake/sample/save-project-json.php")
4+
print(response.text)

exercises/10-get-post-tags/app.py

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

33
def get_post_tags(post_id):
4-
# Your code here
5-
return None
4+
url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"
5+
6+
response = requests.get(url)
7+
8+
if response.status_code == 200:
9+
data = response.json()
10+
11+
for post in data["posts"]:
12+
if post["id"] == post_id:
13+
return post["tags"]
14+
print("No post found")
15+
16+
else:
17+
print("Failed to fetch data from the endpoint.")
618

719

820
print(get_post_tags(146))
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
import requests
22

33
def get_attachment_by_id(attachment_id):
4-
# Your code here
5-
return None
4+
url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"
5+
6+
response = requests.get(url)
7+
8+
if response.status_code == 200:
9+
data = response.json()
10+
11+
for post in data["posts"]:
12+
if "attachments" in post:
13+
for attachment in post['attachments']:
14+
if attachment['id'] == attachment_id:
15+
return attachment['title']
16+
print("No attachment found")
17+
18+
else:
19+
print("Failed to fetch data from the endpoint.")
620

721
print(get_attachment_by_id(137))

exercises/12-post-request/app.py

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

3-
# Your code here
3+
url = 'https://assets.breatheco.de/apis/fake/sample/post.php'
4+
myobj = {'somekey': 'somevalue'}
5+
6+
x = requests.post(url, json = myobj)
7+
8+
print(x.text)

exercises/13-post-request-body/app.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import requests
22

3-
response = requests.post("https://assets.breatheco.de/apis/fake/sample/save-project-json.php")
4-
print(response.text)
3+
url = 'https://assets.breatheco.de/apis/fake/sample/save-project-json.php'
4+
myobj = {"id": 2323,"title": "Very big project"}
5+
headers = {"Content-Type": "application/json"}
6+
7+
x = requests.post(url, json = myobj, headers=headers)
8+
9+
print(x.text)

0 commit comments

Comments
 (0)