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.

26 lines
864 B

import requests
from termcolor import colored
def filtr_prispevky_uzivatele(user_id):
url = "https://jsonplaceholder.typicode.com/posts"
print(f"--- načítám příspěvky od uživatele s ID: {user_id} ---")
try:
response = requests.get(url)
response.raise_for_status()
vsechny_prispevky = response.json()
nalezene_prispevky = []
for p in vsechny_prispevky:
if p['userId'] == user_id:
nalezene_prispevky.append(p)
print(f"Nalezeno {len(nalezene_prispevky)} příspěvků")
print("-"*30)
for p in nalezene_prispevky:
print(f"- {colored(p['title'],'green')}")
except Exception as e:
print(f"chyba:{e}")
if __name__ == "__main__":
uzivatel = int(input("Zadej ID uživatele(1-10):"))
filtr_prispevky_uzivatele(uzivatel)