generated from nogibjj/Mobasserul_Haque_MiniProject2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
108 lines (96 loc) · 3.29 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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import sys
import argparse
from myLib.extract import extract
from myLib.transform_load import load
from myLib.query import (
update_record,
delete_record,
create_record,
general_query,
read_data,
)
def handle_arguments(args):
"""Add action based on initial calls"""
parser = argparse.ArgumentParser(description="ETL-Query script for AirlineSafetyDB")
parser.add_argument(
"action",
choices=[
"extract",
"transform_load",
"update_record",
"delete_record",
"create_record",
"general_query",
"read_data",
],
)
args = parser.parse_args(args[:1])
print(args.action)
if args.action == "update_record":
parser.add_argument("record_id", type=int)
parser.add_argument("airline")
parser.add_argument("avail_seat_km_per_week", type=int)
parser.add_argument("incidents_85_99", type=int)
parser.add_argument("fatal_accidents_85_99", type=int)
parser.add_argument("fatalities_85_99", type=int)
parser.add_argument("incidents_00_14", type=int)
parser.add_argument("fatal_accidents_00_14", type=int)
parser.add_argument("fatalities_00_14", type=int)
if args.action == "create_record":
parser.add_argument("airline")
parser.add_argument("avail_seat_km_per_week", type=int)
parser.add_argument("incidents_85_99", type=int)
parser.add_argument("fatal_accidents_85_99", type=int)
parser.add_argument("fatalities_85_99", type=int)
parser.add_argument("incidents_00_14", type=int)
parser.add_argument("fatal_accidents_00_14", type=int)
parser.add_argument("fatalities_00_14", type=int)
if args.action == "general_query":
parser.add_argument("query")
if args.action == "delete_record":
parser.add_argument("record_id", type=int)
# Parse again with every argument
return parser.parse_args(sys.argv[1:])
def main():
"""Handles all the CLI commands"""
args = handle_arguments(sys.argv[1:])
if args.action == "extract":
print("Extracting data...")
extract()
elif args.action == "transform_load":
print("Transforming data...")
load()
elif args.action == "update_record":
update_record(
args.record_id,
args.airline,
args.avail_seat_km_per_week,
args.incidents_85_99,
args.fatal_accidents_85_99,
args.fatalities_85_99,
args.incidents_00_14,
args.fatal_accidents_00_14,
args.fatalities_00_14,
)
elif args.action == "delete_record":
delete_record(args.record_id)
elif args.action == "create_record":
create_record(
args.airline,
args.avail_seat_km_per_week,
args.incidents_85_99,
args.fatal_accidents_85_99,
args.fatalities_85_99,
args.incidents_00_14,
args.fatal_accidents_00_14,
args.fatalities_00_14,
)
elif args.action == "general_query":
general_query(args.query)
elif args.action == "read_data":
data = read_data()
print(data)
else:
print(f"Unknown action: {args.action}")
if __name__ == "__main__":
main()