You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
691 B
21 lines
691 B
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()
|