8000 Moved things around again to make space for intro and python refreshe… · SWCodeG/testing-python-apps@6af4485 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6af4485

Browse files
committed
Moved things around again to make space for intro and python refresher sections.
1 parent f8688e7 commit 6af4485

File tree

115 files changed

+284
-280
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+284
-280
lines changed

section1/video_code/app.py

Lines changed: 0 additions & 66 deletions
This file was deleted.

section2/video_code/app.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

section3/video_code/app.py

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,66 @@
1-
import os
1+
from blog import Blog
22

3-
from flask import Flask
4-
from flask_restful import Api
5-
from flask_jwt import JWT
63

7-
from security import authenticate, identity
8-
from resources.user import UserRegister
9-
from resources.item import Item, ItemList
10-
from resources.store import Store, StoreList
4+
MENU_PROMPT = '\nEnter "c" to create a blog, "l" to list them, "r" to read one, "p" to write a post, or "q" to quit: '
5+
POST_TEMPLATE = """
6+
--- {} ---
117
12-
app = Flask(__name__)
8+
{}
139
14-
app.config['DEBUG'] = True
10+
"""
1511

16-
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL', 'sqlite:///data.db')
17-
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
18-
app.secret_key = 'jose'
19-
api = Api(app)
12+
blogs = dict()
2013

21-
jwt = JWT(app, authenticate, identity) # /auth
2214

23-
api.add_resource(Store, '/store/<string:name>')
24-
api.add_resource(Item, '/item/<string:name>')
25-
api.add_resource(ItemList, '/items')
26-
api.add_resource(StoreList, '/stores')
15+
def menu():
16+
print_blogs()
17+
selection = input(MENU_PROMPT)
18+
while selection != 'q':
19+
if selection == 'c':
20+
ask_create_blog()
21+
elif selection == 'l':
22+
print_blogs()
23+
elif selection == 'r':
24+
ask_read_blog()
25+
elif selection == 'p':
26+
ask_create_post()
27+
selection = input(MENU_PROMPT)
2728

28-
api.add_resource(UserRegister, '/register')
2929

30-
if __name__ == '__main__':
31-
from db import db
30+
def print_blogs():
31+
for key, blog in blogs.items():
32+
print('- {}'.format(blog))
33+
34+
35+
def ask_create_blog():
36+
title = input("Enter your blog title: ")
37+
author = input("Enter your name: ")
38+
39+
blogs[title] = Blog(title, author)
40+
41+
42+
def ask_read_blog():
43+
title = input("Enter the blog title you want to read: ")
44+
45+
print_posts(blogs[title])
3246

33-
db.init_app(app)
3447

35-
if app.config['DEBUG']:
36-
@app.before_first_request
37-
def create_tables():
38-
db.create_all()
48+
def print_posts(blog):
49+
for post in blog.posts:
50+
print_post(post)
3951

40-
app.run(port=5000)
52+
53+
def print_post(post):
54+
print(POST_TEMPLATE.format(post.title, post.content))
55+
56+
57+
def ask_create_post():
58+
blog = input("Enter the blog title you want to create a post in: ")
59+
title = input("Enter your post title: ")
60+
content = input("Enter your post content: ")
61+
62+
blogs[blog].create_post(title, content)
63+
64+
65+
if __name__ == '__main__':
66+
menu()
File renamed without changes.
File renamed without changes.

section3/video_code/readme.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

section3/video_code/requirements.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0