Пример #1
0
def read_posts():
    end = False
    print()
    blogs = list_blogs()
    print()
    while end is False:
        answer = input(
            "Insert the ID of the blog to read or input (Q) to quit: ")
        if answer.lower() == "q":
            print("Goodbye!")
            end = True
        else:
            for item in blogs:
                if answer == str(item["id"]):
                    print(f"Opening blog: {item['title']}...\n")
                    posts = Post.get_posts(item["id"])
                    if len(posts) == 0:
                        print(f"No posts found in blog {item['title']}")
                    for p in posts:
                        print(f"POST ID:\t{p['id']}\n"
                              f"AUTHOR:\t{p['author']}\n"
                              f"TITLE:\t{p['title']}\n"
                              f"PUBLISHED:\t{p['date']}\n"
                              f"\n"
                              f"{p['contents']}\n\n")
                    end = True
                    break
            else:
                print(f"Blog ID {answer} not found! Try again.")
    print("Goodbye!")