-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.py
80 lines (69 loc) · 2 KB
/
database.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
71
72
73
74
75
76
77
78
79
80
# This is demo that shows how an acutal database works.
# name: David uche
# website: https://daviduche03.github.io
# Email: [email protected]
#initialize an empty database ie: a dictionary
from colorama import init, Fore, Back
from termcolor import colored
from pyfiglet import Figlet
init(autoreset=True)
database = {}
f = Figlet(font='standard')
print(colored(f.renderText(' welcome'), 'green'))
while True:
print (Fore.YELLOW + """
(c) CREATE
(G) GET INPUT BY ID
(A) GET ALL INPUT
(D) DELETE ALL INPUT
(DI) DELETE BY ID
(U) UPDATE
(I) GET ALL ID'S
(E) END PROGRAM'
""")
action = input(Fore.CYAN + 'what do you want to do: ')
if action.upper() == 'C':
id = input(Fore.GREEN + 'Enter your unique id (eg; 123 or 556): ')
name = input('Enter your name: ')
password = input('Enter your password: ')
database[id] = name, password
elif action.upper() == 'G':
id = input('Enter your id: ')
if not id in database:
print (Fore.RED + 'invaid id')
else:
print (f'Your data is {database[id]}')
elif action.upper() == 'A':
print (Fore.BLUE + f"{database}")
if database == {}:
print (Fore.GREEN + 'Database is empty')
elif action.upper() == 'D':
if database == {}:
print ('Database is already cleared')
else:
database.clear()
print ('Bye, database deleted have a nice day')
elif action.upper() == 'DI':
id = input('id: ')
if not id in database:
print (Fore.GREEN + "ID not in DATABASE")
else:
del database[id]
print ('item deleted')
elif action.upper() == 'U':
id = input('id: ')
if not id in database:
print (Fore.BLUE + "ID doesn't match")
else:
name = input('New name: ')
password = input('New password: ')
database[id] = name, password
elif action.upper() == 'I':
db = {"password": 'dave'}
word = input(Fore.GREEN + 'Enter password: ')
if not word in db['password']:
print (Fore.RED + 'Wrong password')
else:
print (database.keys())
elif action.upper() == 'E':
break