-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseeds.py
69 lines (45 loc) · 1.68 KB
/
seeds.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
from model import connect_to_db, db, Restaurant, Offer
from server import app
def kaboom():
print("Kaboom")
Offer.query.delete()
Restaurant.query.delete()
def load_restaurants():
"""Load restaurants from restaurants.txt into database."""
print("Restaurants")
# Read restaurants.txt file and insert data
for row in open("seed_data/restaurants.txt"):
row = row.rstrip()
name, street_address, city, state, zipcode, email, password = row.split("|")
restaurant = Restaurant(name=name,
street_address=street_address,
city=city,
state=state,
zipcode=zipcode,
email=email)
restaurant.set_password(password)
# We need to add to the session or it won't ever be stored
db.session.add(restaurant)
# Once we're done, we should commit our work
db.session.commit()
# def load_offers():
# """Load posts from offers.txt into database."""
# print("Offers")
# # Read offers.txt file and insert data
# for row in open("seed_data/offers.txt"):
# row = row.rstrip()
# restaurant_id, item = row.split("|")
# offer = Offer(restaurant_id=restaurant_id,
# item=item)
# # We need to add to the session or it won't ever be stored
# db.session.add(offer)
# # Once we're done, we should commit our work
# db.session.commit()
if __name__ == "__main__":
connect_to_db(app)
# kaboom()
# In case tables haven't been created, create them
db.create_all()
# Import different types of data
load_restaurants()
# load_offers()