-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
42 lines (34 loc) · 1.03 KB
/
main.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
#
# main.py
# DataLake
#
# Created by Clément Malonda
#
import sys
from database import connect_to_database, init_database, clear_database, list_database, insert_data, create_dataset
OPTIONS = ["init", "insert", "create", "list", "clear"]
def main():
if len(sys.argv) < 2:
print("The command line needs at least one argument in the following list: {}".format(OPTIONS))
exit(1)
try:
assert sys.argv[1] in OPTIONS
except AssertionError or IndexError:
print("First argument in the command line needs to be in following: {}".format(OPTIONS))
exit(1)
cnx = connect_to_database()
cursor = cnx.cursor()
if sys.argv[1] == "init":
init_database(cursor)
elif sys.argv[1] == "insert":
insert_data(cnx, cursor)
elif sys.argv[1] == "create":
create_dataset(cursor)
elif sys.argv[1] == "list":
list_database(cursor)
elif sys.argv[1] == "clear":
clear_database(cursor)
cursor.close()
cnx.close()
if __name__ == "__main__":
main()