forked from olist/TechStartPro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
36 lines (28 loc) · 923 Bytes
/
app.py
File metadata and controls
36 lines (28 loc) · 923 Bytes
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
import csv
from flask import Flask
from models import db, Category
from blueprints.views import products_blueprint
# app = Flask(__name__)
# app.config.from_object('settings')
# app.register_blueprint(products_blueprint)
def create_app(config_filename=None):
app = Flask(__name__)
if config_filename:
app.config.from_pyfile(config_filename)
app.register_blueprint(products_blueprint)
return app
def init_db(app):
""" Initializes my database coming from models """
db.init_app(app)
db.app = app
db.create_all()
categories = Category.query.all()
if categories:
pass
else:
with open('categorias.csv', 'r') as csv_file:
reader = csv.DictReader(csv_file, delimiter=',')
for collumn in reader:
category = Category(name=collumn['nome'])
db.session.add(category)
db.session.commit()