-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_db.py
49 lines (38 loc) · 1.07 KB
/
init_db.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
from getpass import getpass
from flask_bcrypt import generate_password_hash
from goal_tracker import db, create_app
from goal_tracker.models import User, Month
app = create_app()
db.create_all(app=create_app())
with app.app_context():
months = {
'January': 1,
'February': 2,
'March': 3,
'April': 4,
'May': 5,
'June': 6,
'July': 7,
'August': 8,
'September': 9,
'October': 10,
'November': 11,
'December': 12
}
for name, number in months.items():
new_month = Month(
name=name,
number=number
)
db.session.add(new_month)
another_user = 'y'
while another_user.lower() == 'y' or another_user.lower() == 'yes':
username = input('Username: ')
password = getpass()
user = User(
username=username,
password_hash=generate_password_hash(password)
)
db.session.add(user)
another_user = input('Would you like to add another user? (y/N): ')
db.session.commit()