-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatabase_load.py
More file actions
133 lines (95 loc) · 3.81 KB
/
database_load.py
File metadata and controls
133 lines (95 loc) · 3.81 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from database_setup import Category, Base, Item, User
engine = create_engine('sqlite:///shoppingcatalog.db')
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()
# Create dummy user
User1 = User(name="Zach", email="zcjlavallee@gmail.com",
picture='https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png')
session.add(User1)
session.commit()
# Category for Soccer
category1 = Category(user_id=1, name="Soccer")
session.add(category1)
session.commit()
Item1 = Item(user_id=1, name="Soccer Ball", description="Used to play soccer",
price="24.99", category_id=category1.id)
session.add(Item1)
session.commit()
Item2 = Item(user_id=1, name="Cleats", description="Shoes",
price="120.99", category_id=category1.id)
session.add(Item2)
session.commit()
Item3 = Item(user_id=1, name="Jersey", description="Shirt",
price="54.99", category_id=category1.id)
session.add(Item3)
session.commit()
Item4 = Item(user_id=1, name="Whistle", description="Refs whistle",
price="5.99", category_id=category1.id)
session.add(Item4)
session.commit()
Item5 = Item(user_id=1, name="Flag", description="Corner Flag",
price="11.99", category_id=category1.id)
session.add(Item5)
session.commit()
category2 = Category(user_id=1, name="Basketball")
session.add(category2)
session.commit()
Item6 = Item(user_id=1, name="Basketball", description="Used to play basketball",
price="24.99", category_id=category2.id)
session.add(Item6)
session.commit()
Item7 = Item(user_id=1, name="Basketball Shoes", description="Shoes",
price="80.99", category_id=category2.id)
session.add(Item7)
session.commit()
Item8 = Item(user_id=1, name="Hoop", description="Hoop for shooting on",
price="350.99", category_id=category2.id)
session.add(Item8)
session.commit()
Item9 = Item(user_id=1, name="Whistle", description="For the Ref",
price="5.99", category_id=category2.id)
session.add(Item9)
session.commit()
category3 = Category(user_id=1, name="Skiing")
session.add(category3)
session.commit()
Item10 = Item(user_id=1, name="Skis", description="Used to glide down the slope",
price="359.99", category_id=category3.id)
session.add(Item10)
session.commit()
Item11 = Item(user_id=1, name="Ski Poles", description="Used for light inclines",
price="59.99", category_id=category3.id)
session.add(Item11)
session.commit()
Item12 = Item(user_id=1, name="Ski Boots", description="Used to connect yourself to the skis",
price="159.99", category_id=category3.id)
session.add(Item12)
session.commit()
'''
category_json = json.loads("""{
"all_categories": [
{
"name": "Ball",
"description": "Kicked in soccer",
"price": "20.99",
}
]
}""")
for e in category_json['all_categories']:
category_input = Category(name=e['name'],user_id=1, description=['description'], price=['price'], category_id=categoryid)
session.add(cateogry_input)
session.commit()
'''
print("added categories and items with users!")