-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove.py
More file actions
48 lines (44 loc) · 1.71 KB
/
remove.py
File metadata and controls
48 lines (44 loc) · 1.71 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
import sqlite3 as sql
import sys
def remove(arg1, arg2):
with sql.connect("products.db") as connection:
request = '''DELETE FROM products WHERE ''' + arg1 + ''' = ?'''
cursor = connection.cursor()
cursor.execute(request, (arg2,))
connection.commit()
def help():
print('''Removes an item from database
form - python remove.py -arg {object}
write -h --help show this menu.
write -i --id removes an item by id
write -n --name removes item(s) by name
write -q --quantity removes item(s) by quantity
write -p --price removes item(s) by price''')
if __name__ == "__main__":
args = sys.argv
args_len = len(args)
if args_len == 1:
print("Error: not enough arguments, write --help")
elif args_len == 2:
if args[1] == "--help" or args[1] == "-h":
help()
else:
print("Error: not enough arguments, write --help")
elif args_len == 3:
if args[1] == "--help" or args[1] == "-h":
help()
elif args[1] == "-i" or args[1] == "--ip":
if args[2].isnumeric():
remove("item_id", int(args[2]))
elif args[1] == "-n" or args[1] == "--name":
remove("item_nm", args[2])
elif args[1] == "-q" or args[1] == "--quantity":
if args[2].isnumeric():
remove("item_quantity", int(args[2]))
elif args[1] == "-p" or args[1] == "--price":
if args[2].isnumeric():
remove("item_cost", int(args[2]))
else:
print("Error: unknown argument, write --help")
else:
print("Error: too many arguments, write --help")