1 changed files with 26 additions and 0 deletions
@ -0,0 +1,26 @@ |
|||||
|
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) |
||||
Loading…
Reference in new issue