1 changed files with 23 additions and 0 deletions
@ -0,0 +1,23 @@ |
|||
import requests |
|||
from termcolor import colored |
|||
|
|||
def vypis_komentare_prispevku(post_id): |
|||
url = f"https://jsonplaceholder.typicode.com/posts/{post_id}/comments" |
|||
print(f"--- načítám komentaře k příspěvku s ID: {post_id} ---") |
|||
try: |
|||
response = requests.get(url) |
|||
response.raise_for_status() |
|||
komentare = response.json() |
|||
|
|||
for k in komentare: |
|||
print(f"Autor: {colored(k['email'],'blue')}") |
|||
print(f"Komentář: {k['body']}") |
|||
print("-"*16) |
|||
|
|||
except Exception as e: |
|||
print(f"chyba:{e}") |
|||
|
|||
if __name__ == "__main__": |
|||
id_prespevku = int(input("Zadej ID příspěvku " \ |
|||
"pro zobrazení komentářů(1-100):")) |
|||
vypis_komentare_prispevku(id_prespevku) |
|||
Loading…
Reference in new issue