Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .learn/resets/01-creating-a-request/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import requests

url = "https://assets.breatheco.de/apis/fake/sample/404-example.php"
# url = "https://assets.breatheco.de/apis/fake/sample/hello.php"
response = requests.get(url)

print("The response status is: "+str(response.status_code))
3 changes: 3 additions & 0 deletions .learn/resets/02-random-status/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import requests

response = requests.get("https://assets.breatheco.de/apis/fake/sample/random-status.php")
3 changes: 3 additions & 0 deletions .learn/resets/03-response-body/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import requests

url = "https://assets.breatheco.de/apis/fake/sample/random-status.php"
4 changes: 4 additions & 0 deletions .learn/resets/04-response-body-json/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import requests

response = requests.get("https://assets.breatheco.de/apis/fake/sample/time.php")
print(response.text)
3 changes: 3 additions & 0 deletions .learn/resets/05-project-name/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import requests

# Your code here
3 changes: 3 additions & 0 deletions .learn/resets/06-project-list/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import requests

# Your code here
3 changes: 3 additions & 0 deletions .learn/resets/07-project-list-image/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import requests

# Your code here
3 changes: 3 additions & 0 deletions .learn/resets/08-blog-post-author/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import requests

# Your code here
8 changes: 8 additions & 0 deletions .learn/resets/09-list-of-blog-titles/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import requests

def get_titles():
# Your code here
return None


print(get_titles())
8 changes: 8 additions & 0 deletions .learn/resets/10-get-post-tags/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import requests

def get_post_tags(post_id):
# Your code here
return None


print(get_post_tags(146))
7 changes: 7 additions & 0 deletions .learn/resets/11-get-attachment-by-id/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import requests

def get_attachment_by_id(attachment_id):
# Your code here
return None

print(get_attachment_by_id(137))
3 changes: 3 additions & 0 deletions .learn/resets/12-post-request/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import requests

# Your code here
4 changes: 4 additions & 0 deletions .learn/resets/13-post-request-body/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import requests

response = requests.post("https://assets.breatheco.de/apis/fake/sample/save-project-json.php")
print(response.text)
2 changes: 1 addition & 1 deletion exercises/01-creating-a-request/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import requests

url = "https://assets.breatheco.de/apis/fake/sample/404-example.php"
url = "https://assets.breatheco.de/apis/fake/sample/hello.php"
# url = "https://assets.breatheco.de/apis/fake/sample/hello.php"
response = requests.get(url)

Expand Down
11 changes: 11 additions & 0 deletions exercises/02-random-status/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import requests

response = requests.get("https://assets.breatheco.de/apis/fake/sample/random-status.php")

if response.status_code == 404:
print("The URL you asked for is not found")
elif response.status_code == 503:
print("Unavailable right now")
elif response.status_code == 200:
print("Everything went perfect")
elif response.status_code == 400:
print("Something is wrong with the request params")
else:
print("Unknown status code")
7 changes: 7 additions & 0 deletions exercises/03-response-body/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import requests

url = "https://assets.breatheco.de/apis/fake/sample/random-status.php"

response = requests.get(url)

if response.status_code == 200:
print(response.text)
else:
print("Something went wrong")
14 changes: 13 additions & 1 deletion exercises/04-response-body-json/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import requests

response = requests.get("https://assets.breatheco.de/apis/fake/sample/time.php")
print(response.text)

if response.status_code == 200:
# Parsing JSON response
time_data = response.json()

# Extracting hours, minutes, and seconds
hours = time_data["hours"]
minutes = time_data["minutes"]
seconds = time_data["seconds"]

print(f"Current time: {hours} hrs {minutes} min and {seconds} sec")
else:
print("Failed to fetch current time.")
14 changes: 13 additions & 1 deletion exercises/05-project-name/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
import requests

# Your code here
# Your code here
response = requests.get("https://assets.breatheco.de/apis/fake/sample/project1.php")

if response.status_code == 200:
# Parsing JSON response
project_data = response.json()

# Extracting project name
project_name = project_data["name"]

print(project_name)
else:
print("Failed to fetch project data.")
14 changes: 13 additions & 1 deletion exercises/06-project-list/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
import requests

# Your code here
# Your code here
response = requests.get("https://assets.breatheco.de/apis/fake/sample/project_list.php")

if response.status_code == 200:
# Parsing JSON response
project_list = response.json()

# Extracting the name of the second project
second_project_name = project_list[1]["name"]

print(second_project_name)
else:
print("Failed to fetch project list.")
18 changes: 17 additions & 1 deletion exercises/07-project-list-image/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
import requests

# Your code here
# Your code here
response = requests.get("https://assets.breatheco.de/apis/fake/sample/project_list.php")

if response.status_code == 200:
# Parsing JSON response
project_list = response.json()

# Extracting the last project
last_project = project_list[-1]

# Extracting the last image URL
last_image_url = last_project["images"][-1]

# Printing the last image URL
print(last_image_url)
else:
print("Failed to fetch project list.")
17 changes: 16 additions & 1 deletion exercises/08-blog-post-author/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
import requests

# Your code here
# Your code here
responde = requests.get("https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php")

if responde.status_code == 200:
data = responde.json()

first_post = data['posts'][0]

author_dic = first_post['author']

name_author = author_dic['name']

print(name_author)

else:
print("Failed to fetch data from the endpoint.")
19 changes: 18 additions & 1 deletion exercises/09-list-of-blog-titles/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@

def get_titles():
# Your code here
return None
url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"

titles = []

response = requests.get(url)

if response.status_code == 200:
# Parsing JSON response
data = response.json()

for post in data["posts"]:
title = post["title"]
if title:
titles.append(title)
else:
print("Failed to fetch data from the endpoint.")

return titles


print(get_titles())
16 changes: 15 additions & 1 deletion exercises/10-get-post-tags/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,21 @@

def get_post_tags(post_id):
# Your code here
return None
url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"

response = requests.get(url)

if response.status_code == 200:

data = response.json()

for post in data['posts']:
if post["id"] == post_id:
return post["tags"]
print("No post found")

else:
print("Failed to fetch data from the endpoint.")


print(get_post_tags(146))
20 changes: 19 additions & 1 deletion exercises/11-get-attachment-by-id/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

def get_attachment_by_id(attachment_id):
# Your code here
return None
url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"

response = requests.get(url)

if response.status_code == 200:
# Parsing JSON response
data = response.json()

for post in data["posts"]:
# Check if the post has attachments
if "attachments" in post:
# Loop through each attachment
for attachment in post["attachments"]:
if attachment["id"] == attachment_id:
return attachment["title"]

print("No attachment found")
else:
print("Failed to fetch data from the endpoint.")

print(get_attachment_by_id(137))
8 changes: 7 additions & 1 deletion exercises/12-post-request/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import requests

# Your code here
# Your code here
url = "https://assets.breatheco.de/apis/fake/sample/post.php"

response = requests.post(url)

print(response.text)

19 changes: 17 additions & 2 deletions exercises/13-post-request-body/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import requests

response = requests.post("https://assets.breatheco.de/apis/fake/sample/save-project-json.php")
print(response.text)
url = "https://assets.breatheco.de/apis/fake/sample/save-project-json.php"

data = {
"id": 2323,
"title": "Very big project"
}

# Setting the headers
headers = {
"Content-Type": "application/json"
}

# Sending POST request with dictionary data
response = requests.post(url, json=data, headers=headers)

print(response.text)