This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample_data.py
70 lines (59 loc) · 2.39 KB
/
sample_data.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
70
import datetime
from sqlalchemy import create_engine, or_
from sqlalchemy.orm import sessionmaker
from passlib.hash import pbkdf2_sha256
from database import Base, FirstName, LastName, Client, Rent, HotelNumber, User
def insert_sample_data_to_database():
engine = create_engine('sqlite:///hotel.db', echo=False)
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
# connection = engine.connect()
Session = sessionmaker(bind=engine)
session = Session()
clients = [
Client(first_name_id=1, last_name_id=1, age=18, passport_serial='FB', passport_number='123456789'),
Client(first_name_id=2, last_name_id=2, age=20, passport_serial='FB', passport_number='313131313'),
Client(first_name_id=3, last_name_id=2, age=22, passport_serial='FF', passport_number='232323232'),
Client(first_name_id=2, last_name_id=3, age=22, passport_serial='FE', passport_number='121212121'),
]
rents = [
Rent(
hotel_number=1,
total_price=2000,
from_date=datetime.date(2017, 1, 1),
to_date=datetime.date(2017, 1, 3),
clients=[clients[1], clients[2]]
),
Rent(
hotel_number=2,
total_price=10 * 10 * (datetime.date(2017, 10, 27) - datetime.date(2017, 10, 1)).days,
from_date=datetime.date(2017, 10, 1),
to_date=datetime.date(2017, 10, 27),
clients=[clients[0]]
),
Rent(
hotel_number=2,
total_price=10 * (datetime.date(2017, 8, 3) - datetime.date(2017, 7, 27)).days,
from_date=datetime.date(2017, 7, 27),
to_date=datetime.date(2017, 8, 3),
clients=[clients[3]]
)
]
session.add_all([
FirstName(first_name='Ivan'),
FirstName(first_name='Stepan'),
FirstName(first_name='Olga'),
LastName(last_name='Ivanov'),
LastName(last_name='Stepanov'),
LastName(last_name='Petrov'),
HotelNumber(number=1, price_per_night=1000.0, description='VIP'),
HotelNumber(number=2, price_per_night=10.0, description='Cheap'),
HotelNumber(number=3, price_per_night=10.0, description='Cheap'),
*clients,
*rents,
User(name='admin', password_hash=pbkdf2_sha256.hash('admin'))
])
session.commit()
session.close()
if __name__ == '__main__':
insert_sample_data_to_database()