-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_database.py
51 lines (39 loc) · 1.74 KB
/
read_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
import argparse
import json
import sys
from services import flata_db
def arguments():
#Handle command line arguments
parser = argparse.ArgumentParser(description='Function to list the data in the database. Choose one of the arguments.')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-a', '--all', action='store_true', help='List all tables in databse.')
group.add_argument('-l', '--log', action='store_true', help='List the table named "Log".')
group.add_argument('-d', '--driftlaget', action='store_true', help='List the table named "driftlaget".')
parser.add_argument('-db', '--database', help='Full path to database file. Make sure to include file.json after the full path. If left untouched default is mydb.json', default='mydb.json')
args = parser.parse_args()
if len(sys.argv) == 1:
parser.print_help()
sys.exit(2)
return args
def main():
args = arguments()
#Variables
db_path = args.database
if args.all:
tables = 'driftlaget', 'log'
for i in tables:
database_file = flata_db.init_db(db_path, i)
response = database_file.all()
print("Reading data from table:", i, '\n', json.dumps(response, indent=2))
if args.log:
tables = 'log'
database_file = flata_db.init_db(db_path, tables)
response = database_file.all()
print("Reading data from table:", tables, '\n', json.dumps(response, indent=2))
if args.driftlaget:
tables = 'driftlaget'
database_file = flata_db.init_db(db_path, tables)
response = database_file.all()
print("Reading data from table:", tables, '\n', json.dumps(response, indent=2))
if __name__ == '__main__':
main()