3 changed files with 51 additions and 0 deletions
@ -0,0 +1,21 @@ |
|||||
|
import requests |
||||
|
from termcolor import colored |
||||
|
|
||||
|
def vypis_vsechny_prispevky(): |
||||
|
url = "https://jsonplaceholder.typicode.com/posts" |
||||
|
print("--- načítám všechny příspěvky ---") |
||||
|
try: |
||||
|
response = requests.get(url) |
||||
|
response.raise_for_status() |
||||
|
data = response.json() |
||||
|
print(f"Typ stažený dat: {type(data)}") |
||||
|
print(f"Celkový počet: {colored(len(data),'yellow')}") |
||||
|
print("-"*30) |
||||
|
for prispevek in data: |
||||
|
print(f"ID: {prispevek['id']} | \ |
||||
|
Titulek: {colored(prispevek['title'],'cyan')}") |
||||
|
except Exception as e: |
||||
|
print(f"chyba: {e}") |
||||
|
|
||||
|
if __name__ == "__main__": |
||||
|
vypis_vsechny_prispevky() |
||||
@ -0,0 +1,25 @@ |
|||||
|
import requests |
||||
|
from termcolor import colored |
||||
|
|
||||
|
def vypis_urcity_pocet_prispevku(pocet): |
||||
|
url = "https://jsonplaceholder.typicode.com/posts" |
||||
|
intPocet = int(pocet) |
||||
|
print("--- načítám všechny příspěvky ---") |
||||
|
try: |
||||
|
response = requests.get(url) |
||||
|
response.raise_for_status() |
||||
|
data = response.json() |
||||
|
print(f"Typ stažený dat: {type(data)}") |
||||
|
print(f"Celkový počet: {colored(len(data),'yellow')}") |
||||
|
print("-"*30) |
||||
|
|
||||
|
for prispevek in data[:intPocet]: |
||||
|
print(f"ID: {prispevek['id']} | \ |
||||
|
Titulek: {colored(prispevek['title'],'cyan')}") |
||||
|
|
||||
|
except Exception as e: |
||||
|
print(f"chyba: {e}") |
||||
|
|
||||
|
if __name__ == "__main__": |
||||
|
pocet = int(input("kolik příspěvků chceš zobrazit(1-100):")) |
||||
|
vypis_urcity_pocet_prispevku(pocet) |
||||
@ -0,0 +1,5 @@ |
|||||
|
mkdir 22_multivalue_requests |
||||
|
cd 22_multivalue_requests |
||||
|
python -m venv .venv |
||||
|
.venv\Scripts\activate |
||||
|
pip install requests termcolor |
||||
Loading…
Reference in new issue