forked from justinmajetich/AirBnB_clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_0.py
executable file
·49 lines (37 loc) · 1.03 KB
/
main_0.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
#!/usr/bin/python3
"""Doc
"""
import MySQLdb
import sys
import uuid
from models import storage
from models.state import State
def add_states(number=1):
conn = MySQLdb.connect(host="localhost", port=3306, user=sys.argv[1], passwd=sys.argv[2], db=sys.argv[3], charset="utf8")
cur = conn.cursor()
for i in range(number):
cur.execute("INSERT INTO `states` (id, created_at, updated_at, name) VALUES ('{}','2016-03-25 19:42:40','2016-03-25 19:42:40','state{}');".format(str(uuid.uuid4()), i))
conn.commit()
cur.close()
conn.close()
def wrapper_all_type(m_class):
res = {}
try:
res = storage.all(m_class)
except:
res = {}
if res is None or len(res.keys()) == 0:
try:
res = storage.all(m_class.__name__)
except:
res = {}
return res
print(len(wrapper_all_type(State)))
# Initial number of states
add_states(3)
storage.close()
print(len(wrapper_all_type(State)))
# Add new states
add_states(2)
storage.close()
print(len(wrapper_all_type(State)))