24
24
25
25
# insert data
26
26
try :
27
+
27
28
IDs_list = [1 , 2 , 3 , 4 , 5 ]
29
+
28
30
for Id in IDs_list :
31
+
29
32
cr .execute (F"insert into IDs (user_id) values ('{ Id } ')" )
30
33
31
34
except :
35
+
32
36
pass
33
37
34
38
38
42
39
43
# Fetch Data
40
44
cr .execute (f"select user_id from IDs where user_id = '{ u_id } '" )
45
+
41
46
IDs = cr .fetchone ()
42
47
43
48
44
49
# database password
45
50
password = ['skills_database@12345' ]
51
+
46
52
tries = 5
47
53
48
54
@@ -73,6 +79,7 @@ def start_the_app():
73
79
74
80
# Commit and close database
75
81
def commit_and_close ():
82
+
76
83
db .commit ()
77
84
db .close ()
78
85
@@ -82,43 +89,74 @@ def commit_and_close():
82
89
# ------------------
83
90
84
91
def show_all_skills ():
92
+
85
93
# show skills
86
94
cr .execute (f"select * from skills where user_id = '{ u_id } '" )
95
+
87
96
results = cr .fetchall ()
97
+
88
98
print (f"You have '{ len (results )} ' skills" )
99
+
89
100
for row in results :
101
+
90
102
print (f"- Skill name => '{ row [1 ]} ', Skill progress => '{ row [2 ]} '%" )
91
103
104
+
92
105
def add_new_skill ():
106
+
93
107
# insert data
94
108
skill = input ("Write Skill Name: " ).strip ().capitalize ()
109
+
95
110
cr .execute (f"select skill_name from skills where skill_name = '{ skill } ' and user_id = '{ u_id } '" )
111
+
96
112
results = cr .fetchone ()
113
+
97
114
if results == None :
115
+
98
116
progress = input ("Write Skill Progress: " ).strip ()
117
+
99
118
cr .execute (f"insert into skills (user_id, skill_name, skill_progress) values ('{ u_id } ', '{ skill } ', '{ progress } ')" )
119
+
100
120
print (f"'{ skill } ' is added" )
121
+
101
122
else :
123
+
102
124
print (f"This skill '{ skill } ' is already exists" )
125
+
103
126
U_input = input ("Do you want to update its progress? Yes or No " ).strip ().lower ()
127
+
104
128
if U_input == "yes" :
129
+
105
130
new_progress = input ("Write the new Skill Progress: " ).strip ()
131
+
106
132
cr .execute (f"update skills set skill_progress = '{ new_progress } ' where skill_name = '{ skill } ' and user_id = '{ u_id } '" )
133
+
107
134
print (f"'{ skill } ' progress is updated" )
135
+
108
136
else :
137
+
109
138
commit_and_close ()
110
139
140
+
111
141
def delete_skill ():
142
+
112
143
# delete data
113
144
skill = input ("Write Skill Name: " ).strip ().capitalize ()
145
+
114
146
cr .execute (f"delete from skills where skill_name = '{ skill } ' and user_id = '{ u_id } '" )
147
+
115
148
print (f"'{ skill } ' is deleted" )
116
149
150
+
117
151
def update_skill_progress ():
152
+
118
153
# update data
119
154
skill = input ("Write the Skill Name that you want to update its progress: " ).strip ().capitalize ()
155
+
120
156
new_progress = input ("Write the new Skill Progress: " ).strip ()
157
+
121
158
cr .execute (f"update skills set skill_progress = '{ new_progress } ' where skill_name = '{ skill } ' and user_id = '{ u_id } '" )
159
+
122
160
print (f"'{ skill } ' progress is updated" )
123
161
124
162
@@ -128,76 +166,106 @@ def update_skill_progress():
128
166
if user_input in commands_list :
129
167
130
168
if user_input == "s" :
169
+
131
170
show_all_skills ()
132
171
commit_and_close ()
133
172
134
173
elif user_input == "a" :
174
+
135
175
add_new_skill ()
136
176
commit_and_close ()
137
177
138
178
elif user_input == "d" :
179
+
139
180
delete_skill ()
140
181
commit_and_close ()
141
182
142
183
elif user_input == "u" :
184
+
143
185
update_skill_progress ()
144
186
commit_and_close ()
145
187
146
188
else :
189
+
147
190
commit_and_close ()
148
191
print ("App is closed" )
149
192
193
+
150
194
else :
195
+
151
196
print (f"Sorry, Your command '{ user_input } ' not found" )
152
197
153
198
154
199
# check if the u_id is present
155
200
if IDs != None :
201
+
156
202
print (f"Welcome { u_name } !" )
203
+
157
204
start_the_app ()
158
205
159
206
else :
207
+
160
208
print (f"Sorry, You have no access to this database" )
161
209
162
210
163
211
# check if the user want to have access or no
164
212
ques = input ("Do you want to have access to this database? Yes or No " ).strip ().lower ()
165
213
166
214
if ques == 'yes' :
215
+
167
216
user_password = input ("Please enter your password. " ).strip ()
168
217
169
218
# check password
170
219
# if password is right
171
220
if user_password in password :
221
+
172
222
cr .execute (f"insert into IDs (user_id) values ('{ u_id } ')" )
223
+
173
224
print (f"Welcome { u_name } !" )
225
+
174
226
print ("Now you have access to this database" )
227
+
175
228
start_the_app ()
176
229
177
230
# if password is wrong
178
231
else :
232
+
179
233
while user_password not in password :
234
+
180
235
tries -= 1
181
236
182
237
if tries == 0 :
238
+
183
239
print ('Wrong password, Last chance left' )
240
+
184
241
elif tries == 1 :
242
+
185
243
print ('Wrong password, 1 chance left' )
244
+
186
245
else :
246
+
187
247
print (f'Wrong password, { tries } chances left' )
188
248
189
249
user_password = input ("Enter your password. " )
190
250
191
251
if tries == 0 and user_password not in password :
252
+
192
253
print ('All chances are finished!' )
254
+
193
255
print ("You have no access to this database." )
256
+
194
257
break
195
258
196
259
else :
260
+
197
261
cr .execute (f"insert into IDs (user_id) values ('{ u_id } ')" )
262
+
198
263
print (f"Welcome { u_name } !" )
264
+
199
265
print ("Now you have access to this database" )
266
+
200
267
start_the_app ()
201
268
202
269
if ques == 'no' :
270
+
203
271
print ("You Are Not Added." )
0 commit comments