File size: 7,544 Bytes
58f6928
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
from data.database import get_connection, initialize_database

SAMPLE_BOOKS = [
    {
        "title": "1984",
        "author": "George Orwell",
        "category": "Distopya",
        "price": 180.00,
        "stock": 10,
    },
    {
        "title": "Hayvan Çiftliği",
        "author": "George Orwell",
        "category": "Distopya",
        "price": 145.00,
        "stock": 13,
    },
    {
        "title": "Cesur Yeni Dünya",
        "author": "Aldous Huxley",
        "category": "Distopya",
        "price": 195.00,
        "stock": 7,
    },
    {
        "title": "Fahrenheit 451",
        "author": "Ray Bradbury",
        "category": "Distopya",
        "price": 175.00,
        "stock": 8,
    },
    {
        "title": "Dune",
        "author": "Frank Herbert",
        "category": "Bilim Kurgu",
        "price": 320.00,
        "stock": 7,
    },
    {
        "title": "Dune Mesihi",
        "author": "Frank Herbert",
        "category": "Bilim Kurgu",
        "price": 285.00,
        "stock": 5,
    },
    {
        "title": "Vakıf",
        "author": "Isaac Asimov",
        "category": "Bilim Kurgu",
        "price": 260.00,
        "stock": 9,
    },
    {
        "title": "Ben, Robot",
        "author": "Isaac Asimov",
        "category": "Bilim Kurgu",
        "price": 230.00,
        "stock": 6,
    },
    {
        "title": "Marslı",
        "author": "Andy Weir",
        "category": "Bilim Kurgu",
        "price": 290.00,
        "stock": 8,
    },
    {
        "title": "Otostopçunun Galaksi Rehberi",
        "author": "Douglas Adams",
        "category": "Bilim Kurgu",
        "price": 245.00,
        "stock": 11,
    },
    {
        "title": "Simyacı",
        "author": "Paulo Coelho",
        "category": "Roman",
        "price": 150.00,
        "stock": 8,
    },
    {
        "title": "Körlük",
        "author": "José Saramago",
        "category": "Roman",
        "price": 210.00,
        "stock": 4,
    },
    {
        "title": "Serenad",
        "author": "Zülfü Livaneli",
        "category": "Roman",
        "price": 225.00,
        "stock": 10,
    },
    {
        "title": "Kürk Mantolu Madonna",
        "author": "Sabahattin Ali",
        "category": "Roman",
        "price": 135.00,
        "stock": 15,
    },
    {
        "title": "İnce Memed",
        "author": "Yaşar Kemal",
        "category": "Roman",
        "price": 280.00,
        "stock": 7,
    },
    {
        "title": "Tutunamayanlar",
        "author": "Oğuz Atay",
        "category": "Roman",
        "price": 340.00,
        "stock": 6,
    },
    {
        "title": "Saatleri Ayarlama Enstitüsü",
        "author": "Ahmet Hamdi Tanpınar",
        "category": "Roman",
        "price": 220.00,
        "stock": 8,
    },
    {
        "title": "Suç ve Ceza",
        "author": "Fyodor Dostoyevski",
        "category": "Klasik",
        "price": 240.00,
        "stock": 6,
    },
    {
        "title": "Karamazov Kardeşler",
        "author": "Fyodor Dostoyevski",
        "category": "Klasik",
        "price": 390.00,
        "stock": 4,
    },
    {
        "title": "Sefiller",
        "author": "Victor Hugo",
        "category": "Klasik",
        "price": 360.00,
        "stock": 5,
    },
    {
        "title": "Monte Cristo Kontu",
        "author": "Alexandre Dumas",
        "category": "Klasik",
        "price": 410.00,
        "stock": 3,
    },
    {
        "title": "Anna Karenina",
        "author": "Lev Tolstoy",
        "category": "Klasik",
        "price": 375.00,
        "stock": 5,
    },
    {
        "title": "Vadideki Zambak",
        "author": "Honoré de Balzac",
        "category": "Klasik",
        "price": 170.00,
        "stock": 7,
    },
    {
        "title": "Yüzüklerin Efendisi",
        "author": "J. R. R. Tolkien",
        "category": "Fantastik",
        "price": 450.00,
        "stock": 5,
    },
    {
        "title": "Hobbit",
        "author": "J. R. R. Tolkien",
        "category": "Fantastik",
        "price": 275.00,
        "stock": 9,
    },
    {
        "title": "Harry Potter ve Felsefe Taşı",
        "author": "J. K. Rowling",
        "category": "Fantastik",
        "price": 260.00,
        "stock": 12,
    },
    {
        "title": "Taht Oyunları",
        "author": "George R. R. Martin",
        "category": "Fantastik",
        "price": 390.00,
        "stock": 6,
    },
    {
        "title": "Küçük Prens",
        "author": "Antoine de Saint-Exupéry",
        "category": "Çocuk",
        "price": 120.00,
        "stock": 12,
    },
    {
        "title": "Şeker Portakalı",
        "author": "José Mauro de Vasconcelos",
        "category": "Çocuk",
        "price": 155.00,
        "stock": 10,
    },
    {
        "title": "Momo",
        "author": "Michael Ende",
        "category": "Çocuk",
        "price": 190.00,
        "stock": 8,
    },
    {
        "title": "Sapiens",
        "author": "Yuval Noah Harari",
        "category": "Tarih",
        "price": 290.00,
        "stock": 9,
    },
    {
        "title": "Homo Deus",
        "author": "Yuval Noah Harari",
        "category": "Tarih",
        "price": 310.00,
        "stock": 7,
    },
    {
        "title": "Nutuk",
        "author": "Mustafa Kemal Atatürk",
        "category": "Tarih",
        "price": 250.00,
        "stock": 14,
    },
    {
        "title": "Doğu Ekspresinde Cinayet",
        "author": "Agatha Christie",
        "category": "Polisiye",
        "price": 185.00,
        "stock": 9,
    },
    {
        "title": "Sherlock Holmes: Kızıl Dosya",
        "author": "Arthur Conan Doyle",
        "category": "Polisiye",
        "price": 165.00,
        "stock": 8,
    },
    {
        "title": "Ejderha Dövmeli Kız",
        "author": "Stieg Larsson",
        "category": "Polisiye",
        "price": 280.00,
        "stock": 5,
    },
    {
        "title": "İnsanın Anlam Arayışı",
        "author": "Viktor E. Frankl",
        "category": "Psikoloji",
        "price": 190.00,
        "stock": 11,
    },
    {
        "title": "Düşünme, Hızlı ve Yavaş",
        "author": "Daniel Kahneman",
        "category": "Psikoloji",
        "price": 350.00,
        "stock": 6,
    },
    {
        "title": "Sofinin Dünyası",
        "author": "Jostein Gaarder",
        "category": "Felsefe",
        "price": 275.00,
        "stock": 8,
    },
    {
        "title": "Devlet",
        "author": "Platon",
        "category": "Felsefe",
        "price": 215.00,
        "stock": 7,
    },
]


def seed_books() -> None:
    """Örnek kitapları veritabanına ekler."""

    initialize_database()

    query = """
        INSERT OR IGNORE INTO books (
            title,
            author,
            category,
            price,
            stock
        )
        VALUES (?, ?, ?, ?, ?)
    """

    with get_connection() as connection:
        for book in SAMPLE_BOOKS:
            connection.execute(
                query,
                (
                    book["title"],
                    book["author"],
                    book["category"],
                    book["price"],
                    book["stock"],
                ),
            )

        connection.commit()

        book_count = connection.execute(
            "SELECT COUNT(*) AS total FROM books"
        ).fetchone()["total"]

    print("Örnek kitaplar başarıyla eklendi.")
    print(f"Veritabanındaki toplam kitap sayısı: {book_count}")


if __name__ == "__main__":
    seed_books()