forked from werhereitacademy/Python_Modul_Week_2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboek_transacties.py
More file actions
151 lines (123 loc) · 4.96 KB
/
boek_transacties.py
File metadata and controls
151 lines (123 loc) · 4.96 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import json
import os
BOEKEN_BESTAND = "boeken.json"
UITLEEN_BESTAND = "uitleeningen.json"
#-------------------------------------------------------
def lees_boeken():
if not os.path.exists(BOEKEN_BESTAND):
return[]
with open(BOEKEN_BESTAND, "r", encoding="utf-8") as file:
try:
return json.load(file)
except json.JSONDecodeError:
return[]
#-----------------------------------------------------------------
def schrijf_boeken(boeken):
with open(BOEKEN_BESTAND, "w",encoding="utf-8") as file:
json.dump(boeken, file, ensure_ascii=False, indent=4)
#---------------------------------------------------------------------
# def boek_lijst():
# boeken = lees_boeken()
# if not boeken:
# print("henuz hic kitap eklenmemis ")
# return
# boeken_sorted= sorted(boeken,key=lambda b: b["baslik"].lower())
# print("\n==== KITAP LISTESI ====")
# for boek in boeken_sorted:
# print(f"Barkod: {boek['barkod']} | Adi:{boek['baslik']} |"
# f"Yil: {boek['yil']} | Yazar: {boek['yazar']}")
def boek_lijst():
boeken = lees_boeken() # ← düzeltildi
if not boeken:
print("Henüz hiç kitap eklenmemiş.")
return
boeken_sorted = sorted(boeken, key=lambda b: b["baslik"].lower())
print("\n==== KİTAP LİSTESİ ====")
for boek in boeken_sorted:
print(f"barkod: {boek['barkod']} | Adı: {boek['baslik']} | "
f"Yıl: {boek['yil']} | Yazar: {boek['yazar']}")
#--------------------------------------------------------------------------------
# def boek_toevoegen():
# boeken = lees_boeken()
# barkod= input("Barkod numarasi: ").strip()
# for boek in boeken:
# if str(boek["Barkod"])== barkod:
# print("bu barkod zaten kayitli!")
# return
# baslik= input("Kitap adi: ").strip()
# yil= input("Yil: ").strip()
# yazar = input("Yazar: ").strip()
# nieuw_boek={
# "Barkod": barkod,
# "Kitap_Adi": baslik,
# "yil": yil,
# "Yazar": yazar,
# "tur" : tur
# }
# boeken.append(nieuw_boek)
# schrijf_boeken(boeken)
# print(" Yeni kitap basariyle eklendi! ")
def boek_toevoegen():
boeken = lees_boeken()
barkod = input("Barkod numarası: ").strip()
for boek in boeken:
if str(boek["barkod"]) == barkod:
print("Bu barkod zaten kayıtlı!")
return
baslik = input("Kitap adı: ").strip()
yil = input("Yıl: ").strip()
yazar = input("Yazar: ").strip()
tur = input("Tür: ").strip()
nieuw_boek = {
"barkod": barkod,
"baslik": baslik,
"yil": yil,
"yazar": yazar,
"tur": tur
}
boeken.append(nieuw_boek)
schrijf_boeken(boeken)
print("Yeni kitap başarıyla eklendi!")
#---------------------------------------------------------------------------------------------------
def boek_bijwerken():
boeken=lees_boeken()
barkod = input("Guncellenecek kitabin barkodu: ").strip()
for boek in boeken:
if str(boek["barkod"]) == barkod:
print(f"Mevcut bilgiler: {boek}")
boek["baslik"] = input("Yeni kitap adi(bos birakmak icin enter):") or boek["baslik"]
boek["yil"] = input("yil ( bos birakmak icin enter):") or boek["yil"]
boek["yazar"] = input("Yeni yazar ( bos birakmak icin enter):") or boek["yazar"]
schrijf_boeken(boeken)
print("Kitap basariyla guncellendi!")
return
print ("Bu barkoda sahip kitap bulunamadi")
#----------------------------------------------------------------------------------------------------------
def boek_zoeken():
boeken = lees_boeken()
if not boeken:
print("Henuz kitap eklenmemis ")
return
keyword= input("Aranacak kitap adi veya yazari: ").lower().strip()
resultaten= [
boek for boek in boeken
if keyword in boek["baslik"].lower() or keyword in boek["yazar"].lower()
]
if not resultaten:
print(" Hicbir sonuc bulunamadi.")
return
print("\n=== ARAMA SONUCLARI ====")
for boek in resultaten:
print(f"{ boek['baslik']} - {boek['yazar']} - ({boek['yil']})")
print(f"=== {len(resultaten)} kitap bulundu.====")
#------------------------------------------------------------------------------------------------------------
def boek_verwijderen():
boeken= lees_boeken()
barkod= input(" Silmek istediginiz kitabin barkodu: ").strip()
nieuwe_lijst= [b for b in boeken if str(b["barkod"]) != barkod]
if len(boeken) == len(nieuwe_lijst):
print(" Bu barkoda sahip kitap bulunamadi.")
else:
schrijf_boeken(nieuwe_lijst)
print(" Kitap basariyla silindi! ")
#-------------------------------------------------------------------------------------------------------------