-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
36 lines (30 loc) · 1.06 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
import argparse
import json
from beautifultable import BeautifulTable
class Plugin:
def __init__(self) -> None:
pass
def plugin_parser(self, subparser: argparse.ArgumentParser) -> None:
display_parser = subparser.add_parser("show", help="Display a database file")
display_parser.add_argument(
"file_name", help="Name of the database file to display"
)
def action(self, args: argparse.Namespace) -> None:
"""
Print a database file
:param str file_name: The absolute path to the DB file
"""
table = BeautifulTable()
with open(args.file_name) as jsondoc:
data = json.load(jsondoc)
real_data = data["data"]
try:
header = list(data["data"][0].keys())
except IndexError:
print("Database is empty.")
return 1
for all_data in real_data:
table.rows.append(list(all_data.values()))
table.columns.header = header
print(table)
return 0