-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.py
38 lines (28 loc) · 1.05 KB
/
seed.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
"""Script to seed database"""
import os #module from Python's library, code related to working with your computer's operating system
import json
from random import choice, randint
from datetime import datetime
import models
import server
os.system('dropdb rooms')
os.system('createdb rooms')
models.connect_to_db(server.app)
models.db.create_all()
#Create 10 users
for n in range(10):
username = f'user{n}'
email = f'user{n}@test.com' #unique email
password = f'test{n}'
user = models.User(username=username, email=email, password=password)
models.db.session.add(user)
models.db.session.commit()
# Create rooms, store them in list so we can use them
# to create fake posts, likes and comments later
posts_in_db = []
posts = ["living room", "bedroom", "kitchen", "patio", "home office"]
db_room = models.Post(title='test', date_posted=datetime.now(), content='test test test',
user_id=1)
models.db.session.add(db_room)
models.db.session.commit()
posts_in_db.append(db_room)