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.
23 lines
741 B
23 lines
741 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 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)
|