Skip to content

Commit 759566f

Browse files
author
david allen
committed
Delete profile, print profile, and pasword text
1 parent 405d55a commit 759566f

File tree

3 files changed

+109
-19
lines changed

3 files changed

+109
-19
lines changed

capstone_kv_impl.py

Lines changed: 108 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import string
12
from kivy.app import App
23
from kivy.lang import Builder
34
from kivy.uix.screenmanager import ScreenManager, Screen
@@ -35,7 +36,24 @@ def db_init(db_name = 'profile.db', table_name = "users"):
3536

3637
return
3738

38-
def db_newprofile(
39+
def db_un_exists(un, db_name = 'profile.db'):
40+
conn = sqlite3.connect(db_name)
41+
c = conn.cursor()
42+
c.execute(f"""SELECT un
43+
FROM users
44+
WHERE un = '{un}'
45+
""")
46+
un_result = c.fetchall()
47+
48+
result = True if len(un_result) else False
49+
50+
print(f'db_un_exists("{un}") result = "{result}"')
51+
52+
conn.close()
53+
54+
return result
55+
56+
def db_profile_new(
3957
un,
4058
pw,
4159
fn,
@@ -69,7 +87,62 @@ def db_newprofile(
6987

7088
return
7189

72-
def db_login(un, pw, db_name = 'profile.db'):
90+
def db_profile_print(*args, **kwargs):
91+
uns = []
92+
print_all = False
93+
profiles = []
94+
if len(args):
95+
for arg in args:
96+
if type(arg) == str:
97+
uns.append(arg)
98+
if type(arg) == list and len(arg) and type(arg[0]) == str:
99+
for un in arg:
100+
uns.append(un)
101+
102+
# print(f'uns = {uns}')
103+
104+
# handle default kwargs
105+
if 'db_name' not in kwargs.keys():
106+
db_name = 'profile.db'
107+
pass
108+
else:
109+
db_name = kwargs['db_name']
110+
pass
111+
if 'all' in kwargs.keys():
112+
# print all profiles
113+
print_all = kwargs['all']
114+
pass
115+
116+
conn = sqlite3.connect(db_name)
117+
c = conn.cursor()
118+
if print_all:
119+
c.execute(f"""SELECT rowid, *
120+
FROM users
121+
ORDER BY un
122+
""")
123+
profiles = c.fetchall()
124+
pass
125+
else:
126+
for un in uns:
127+
print(f'un = {un}')
128+
c.execute(f"""SELECT rowid, *
129+
FROM users
130+
WHERE un = '{un}'
131+
""")
132+
profiles.append(c.fetchone())
133+
134+
135+
result = True if len(profiles) else False
136+
137+
print(f'db_profile_print("*{args}, **{kwargs}") profiles =')
138+
for profile in profiles:
139+
print(profile)
140+
141+
conn.close()
142+
143+
return result
144+
145+
def db_un_login(un, pw, db_name = 'profile.db'):
73146
conn = sqlite3.connect(db_name)
74147
c = conn.cursor()
75148
c.execute(f"""SELECT rowid, first_name
@@ -83,16 +156,20 @@ def db_login(un, pw, db_name = 'profile.db'):
83156

84157
result = True if len(first_name) else False
85158

86-
print(f'db_login("{un}", "{pw}") result = "{result}"')
159+
print(f'db_un_login("{un}", "{pw}") result = "{result}"')
87160

88161
conn.close()
89162

90163
return result
91164

92-
def db_update_profile(un, **kwargs):
165+
def db_profile_update(un, **kwargs):
93166
# handle default kwargs
94-
if "db_name" not in kwargs.keys():
167+
if 'db_name' not in kwargs.keys():
95168
db_name = 'profile.db'
169+
pass
170+
else:
171+
db_name = kwargs['db_name']
172+
pass
96173

97174
conn = sqlite3.connect(db_name)
98175
c = conn.cursor()
@@ -102,29 +179,35 @@ def db_update_profile(un, **kwargs):
102179
WHERE un = '{un}'
103180
""")
104181

105-
print(f'db_update_profile({un}, {kwargs}) executed.')
182+
print(f'db_profile_update({un}, {kwargs}) executed.')
106183

107184
conn.commit()
108185
conn.close()
109186

110187
return
111188

112-
def db_un_exists(un, db_name = 'profile.db'):
189+
def db_profile_delete(un, **kwargs):
190+
# handle default kwargs
191+
if 'db_name' not in kwargs.keys():
192+
db_name = 'profile.db'
193+
pass
194+
else:
195+
db_name = kwargs['db_name']
196+
pass
197+
113198
conn = sqlite3.connect(db_name)
114199
c = conn.cursor()
115-
c.execute(f"""SELECT un
116-
FROM users
200+
201+
c.execute(f"""DELETE from users
117202
WHERE un = '{un}'
118203
""")
119-
un_result = c.fetchall()
120-
121-
result = True if len(un_result) else False
122204

123-
print(f'db_un_exists("{un}") result = "{result}"')
205+
print(f'db_profile_delete({un}) profile deleted, if it existed in the first place.')
124206

207+
conn.commit()
125208
conn.close()
126209

127-
return result
210+
return
128211

129212
# ----------------------
130213
# Kivy Window management
@@ -165,26 +248,32 @@ def build(self):
165248
if __name__ == "__main__":
166249
# Database initialization and tests
167250
db_init()
168-
db_newprofile(
251+
db_un_exists('userNameThatDoesNotExist')
252+
db_profile_delete('userNameThatDoesNotExist')
253+
db_profile_delete('davidDelSol')
254+
db_profile_new(
169255
'davidDelSol',
170256
'encrypted?',
171257
'david',
172258
'aloka',
173259
'test@preform.io',
174260
'salsa,extended intelligence,marathon running in a full suit'
175261
)
176-
db_newprofile(
262+
db_profile_new(
177263
'Python733t',
178264
'encrypted?',
179265
'Doroteo ',
180266
'Bonilla',
181267
'doabonilla@yahoo.com',
182268
'work,school,sleep,repeat'
183269
)
184-
db_login('davidDelSol', 'encrypted?')
185-
db_update_profile('davidDelSol', pw = 'definitelyNotEncripted!')
186-
db_login('davidDelSol', 'definitelyNotEncripted!')
270+
db_un_login('davidDelSol', 'encrypted?')
271+
db_profile_update('davidDelSol', pw = 'definitelyNotEncripted!')
272+
db_un_login('davidDelSol', 'definitelyNotEncripted!')
187273
db_un_exists('davidDelSol')
274+
db_profile_print(all = True)
275+
db_profile_print(['Python733t'])
276+
db_profile_print('Python733t')
188277

189278
# Run Kivy app
190279
MyMainApp().run()

my.kv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ WindowManager:
4141
TextInput:
4242
id: passw
4343
multiline: False
44+
password: True
4445

4546
Button:
4647
text: "Submit"

profile.db

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)