-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.py
63 lines (57 loc) · 1.63 KB
/
database.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
import sys
import json, uuid
from random import uniform, randint
from datetime import datetime, date
from wheels import wheels, db
from wheels.models import User, Vehicle, Review
def init_user_db():
db.drop_all()
db.create_all()
admin = User(email='[email protected]',
guid = uuid.uuid4().hex,
phone='333-333-3333',
name='Gleb',
surname='Ignatiev',
password='pass123',
avatar='admin.png',
reg_date=datetime.utcnow(),
bday=date(1995, 03, 31),
confirmed=True,
about_me='')
db.session.add(admin)
db.session.commit()
users = User.query.all()
print ('Email: {0}').format(users[0].email)
with open('vehicle_base.json') as f:
cars = json.load(f)
i = 1
for car in cars:
show_name = '{0} {1} ({2})'.format(car['brand'], car['model'], 'before 1960' if car['year'] < 1960 else car['year'])
v = Vehicle(brand=car['brand'],
model=car['model'],
year=car['year'],
show_name=show_name,
price=car['price'],
rating=uniform(1.0, 5.0),
review_count=randint(1, 30),
description=car['description'],
photo=str(i) + '.jpg', #car['show_name'].replace(' ', '_') + '.jpg',
owner=admin)
i += 1
print v.show_name, v.price, v.rating
db.session.add(v)
db.session.commit()
the_review = Review(rating=1,
text='sample review',
timestamp=datetime.utcnow(),
uid=1, ownid=1, vid=1)
db.session.add(the_review)
db.session.commit()
db.session.delete(the_review)
db.session.commit()
if __name__ == "__main__":
if len(sys.argv) > 1:
if sys.argv[1] == 'init':
init_user_db()
else:
print 'Usage: flask/bin/python database.py init'