1 changed files with 20 additions and 0 deletions
@ -0,0 +1,20 @@ |
|||||
|
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 (Pole/Array) ---") |
||||
|
try: |
||||
|
response = requests.get(url) |
||||
|
response.raise_for_status() |
||||
|
data = response.json() |
||||
|
print(f"Typ stažených dat: {type(data)}") |
||||
|
print(f"celkový počet příspěvků: {colored(len(data),'yellow')}") |
||||
|
print("-"*30) |
||||
|
for prispevek in data[:10]: |
||||
|
print(f"ID: {prispevek['id']} | titulek: {colored(prispevek['title'],'cyan')}") |
||||
|
except Exception as e: |
||||
|
print(f"Chyba: {e}") |
||||
|
|
||||
|
if __name__ == "__main__": |
||||
|
vypis_vsechny_prispevky() |
||||
Loading…
Reference in new issue