-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
78 lines (54 loc) · 1.68 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from blog import Blog
from post import Post
MENU_PROMPT = ('Enter "c" to create a blog, '
'"l" to list blogs, '
'"r" to read blogs, '
'"p" to create a post, '
'or "q" to quit: ')
POST_TEMPLATE = '''
--- {} ---
{}
'''
blogs = dict() # blog_name : Blog object
def menu():
# show the use the available blogs
# let the use make a choice
# do something with that choice
# eventualy exit
print_blogs()
selection = input(MENU_PROMPT)
while selection != 'q':
if selection == 'c':
ask_create_blog()
elif selection == 'l':
print_blogs()
elif selection == 'r':
ask_read_blog()
elif selection == 'p':
ask_create_post()
selection = input(MENU_PROMPT)
def print_blogs():
# print available blogs
print("Blogs!")
for key, blog in blogs.items(): # [(blog_name, Blog), (blog_name, Blog)]
print(f'- {blog}')
def print_posts(blog):
for post in blog.posts:
print_post(post)
def print_post(post):
print(POST_TEMPLATE.format(post.title, post.content))
def ask_create_blog():
title = input("Enter your blog title: ")
author = input("Enter your name: ")
b = Blog(title, author)
blogs[title] = b
# sau
# blogs[title] = Blog(title, author)
def ask_read_blog():
title = input("Enter the blog title: ")
print_posts(blogs[title])
def ask_create_post():
blog_name = input("Enter the blog title you want to post in: ")
title = input("Enter the title of the post: ")
content = input("Enter the content of the post: ")
blogs[blog_name].create_post(title, content)