def read_posts(): svc = BlogClient() response = svc.all_entries() posts = response.json() print() for idx, p in enumerate(posts, 1): print(" {}. [{:,} views] {}".format(idx, p.get('view_count'), p.get('title'))) print() selected = int(input('Which number to view?')) selected_id = posts[selected - 1].get('id') response = svc.entry_by_id(selected_id) selected_post = response.json() print("Details for selected_post: {}".format(selected_post.get('id'))) print("Title: " + selected_post.get('title')) print("Written: " + selected_post.get('published')) print("Content: " + selected_post.get('content')) print() print()
def read_posts(): svc = BlogClient() response = svc.all_entries() response.raise_for_status() posts = response.json() for idx, p in enumerate(posts, 1): print(" * {}. [{} views] {}".format(idx, p.get('view_count'), p.get('title'))) print() selected = int(input('Which number to view? ')) selected_id = posts[selected - 1].get('id') print(selected_id)
def read_entries(): svc = BlogClient() response = svc.all_entries() posts = response.json() for idx, p in enumerate(posts, 1): print(f'{idx}. {p.get("view_count")} - {p.get("title")}') selected = int(input('Which post do you want to view? - ')) selected_id = posts[selected - 1].get('id') response = svc.entry_by_id(selected_id) selected_post = response.json() print() print(f'Fetching blog with id: {selected_id}') print(f'Title: {selected_post.get("title")}') print(f'Published on: {selected_post.get("published")}') print(f'Total views: {selected_post.get("view_count")}') print(f'Content: {selected_post.get("content")}')
def read_posts(): svc = BlogClient() response = svc.all_entries() posts = response.json() for idx, p in enumerate(posts, 1): print(f"{idx}. {p.get('view_count')} views for {p.get('title')}") print() selected = int(input('Which number to view? ')) selected_id = posts[selected - 1].get('id') response = svc.entry_by_id(selected_id) selected_post = response.json() print('Details of the selected post: {}'.format(selected_id)) print('Title: {}'.format(selected_post.get('title'))) print('Written: {}'.format(selected_post.get('published'))) print('Content: {}'.format(selected_post.get('content'))) print() print()
def read_post(): svc = BlogClient() response = svc.all_entries() response.raise_for_status() posts = response.json() for idx, p in enumerate(posts, 1): print(f" {idx}. [{p.get('view_count')} views] {p.get('title')}") print(type(response), response) selected = int(input("Which number do you want to view? ")) selected_id = posts[selected - 1].get('id') response = svc.entry_by_id(selected_id) response.raise_for_status() selected_post = response.json() print(f"Details for selected_post: {selected_post.get('id')}") print(f"Title: {selected_post.get('title')}") print(f"Written: {selected_post.get('published')}") print(f"Content: {selected_post.get('content')}") print() print()