Пример #1
0
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()
Пример #2
0
def write_entries():
    svc = BlogClient()
    title = input('Title: ')
    content = input('Body contents: ')
    view_count = int(input('View count (int): '))
    # published = datetime.now().isoformat()

    resp = svc.add_new_entry(title, content, view_count)
    print()
    print(f'Created new entry with ID: {resp.json().get("id")}')
    print()
Пример #3
0
def write_post():
    svc = BlogClient()

    title = input("Title: ")
    content = input("body contents: ")
    view_count = int(input("view count (int): "))

    r = svc.create_new_entry(title, content, view_count)

    print('\n')
    print("Created new post succesfully: {}".format(r.json().get('id')))
    print('\n')
Пример #4
0
def write_posts():
    svc = BlogClient()

    title = input('Title: ')
    views = int(input('View count: '))
    content = input('Content: ')

    resp = svc.add_new_entry(title, content, views)

    print()
    print('Create the new post successfully: {}'.format(resp.json().get('id')))
    print()
Пример #5
0
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)
Пример #6
0
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")}')
Пример #7
0
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()
Пример #8
0
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()