Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f292b0e

Browse files
committed
Exercises 1 to 8
1 parent 9ea60a2 commit f292b0e

File tree

17 files changed

+124
-8
lines changed

17 files changed

+124
-8
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+
# url = "https://assets.breatheco.de/apis/fake/sample/404-example.php"
4+
url = "https://assets.breatheco.de/apis/fake/sample/hello.php"
5+
response = requests.get(url)
6+
7+
print("The response status is: "+str(response.status_code))
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import requests
2+
3+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/random-status.php")
4+
5+
status = response.status_code
6+
7+
if status == 404:
8+
print("The URL you asked for is not found")
9+
elif status == 503:
10+
print("Unavailable right now")
11+
elif status == 200:
12+
print("Everything went perfect")
13+
elif status == 400:
14+
print("Something is wrong with the request params")
15+
else:
16+
print("Unknown status code")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import requests
2+
3+
url = "https://assets.breatheco.de/apis/fake/sample/random-status.php"
4+
5+
response = requests.get(url)
6+
7+
if response.status_code == 200:
8+
print(response.text)
9+
else:
10+
print("Something went wrong")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import requests
2+
3+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/time.php")
4+
time_dict = response.json()
5+
hrs = time_dict['hours']
6+
mins = time_dict['minutes']
7+
sec = time_dict['seconds']
8+
print(f'Current time: {hrs} hrs {mins} min and {sec} sec')

‎.learn/resets/05-project-name/app.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import requests
2+
3+
# Your code here
4+
response = requests.get('https://assets.breatheco.de/apis/fake/sample/project1.php')
5+
6+
if response.status_code == 200:
7+
response_dict = response.json()
8+
name = response_dict['name']
9+
print(name)
10+
else:
11+
print("Data extraction failed")

‎.learn/resets/06-project-list/app.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import requests
2+
3+
# Your code here
4+
response = requests.get('https://assets.breatheco.de/apis/fake/sample/project_list.php')
5+
response_dict = response.json()
6+
print(response_dict[1]['name'])
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import requests
2+
3+
# Your code here
4+
response = requests.get('https://assets.breatheco.de/apis/fake/sample/project_list.php')
5+
response_dict = response.json()
6+
print(response_dict[-1]['images'][-1])
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import requests
2+
3+
def get_titles():
4+
# Your code here
5+
return None
6+
7+
8+
print(get_titles())
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import requests
22

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

7-
print("The response status is: "+str(response.status_code))
7+
print("The response status is: "+str(response.status_code))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /