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.
 
 

19 lines
706 B

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 komentáře 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("-"*20)
except Exception as e:
print(f"chyba:{e}")
if __name__ == "__main__":
id_prisevku = int(input("Zadej ID příspěvku pro komentáře(1-100):"))
vypis_komentare_prispevku(id_prisevku)