mirror of
https://github.com/kevinveenbirkenbach/baserow-ifto.git
synced 2024-11-25 20:31:04 +01:00
Implemented linked fields parameter
This commit is contained in:
parent
74e5f3e73f
commit
ef8fe33a5d
@ -1,28 +1,30 @@
|
||||
# controller.py
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from baserow_api import BaserowAPI
|
||||
import view
|
||||
|
||||
def handle_output(quiet,data):
|
||||
if not quiet:
|
||||
view.print_json_output(data)
|
||||
|
||||
def main():
|
||||
args = parse_arguments()
|
||||
api = BaserowAPI(args.base_url, args.api_key, args.verbose)
|
||||
|
||||
if not args.database_id and not args.table_ids:
|
||||
view.print_error_message("Either database_id or table_ids must be provided.")
|
||||
exit(1)
|
||||
|
||||
if args.table_ids:
|
||||
tables_data = fetch_table_data(api, args.table_ids)
|
||||
if args.matrix:
|
||||
if "linked_fields" in args.output:
|
||||
linked_fields_data = api.get_link_fields_for_all_tables(tables_data)
|
||||
handle_output(args.quiet, linked_fields_data)
|
||||
|
||||
if "matrix" in args.output:
|
||||
merged_data = api.merge_tables_on_reference(tables_data)
|
||||
if not args.quiet:
|
||||
view.print_json_output(merged_data)
|
||||
else:
|
||||
if not args.quiet:
|
||||
view.print_json_output(tables_data)
|
||||
else:
|
||||
handle_output(args.quiet, merged_data)
|
||||
|
||||
if "tables" in args.output:
|
||||
handle_output(args.quiet, tables_data)
|
||||
|
||||
if args.database_id:
|
||||
all_data = api.get_all_data_from_database(args.database_id)
|
||||
if not args.quiet:
|
||||
view.print_json_output(all_data)
|
||||
@ -33,9 +35,8 @@ def parse_arguments():
|
||||
parser.add_argument("api_key", help="Your Baserow API key.")
|
||||
parser.add_argument("--database_id", help="ID of the Baserow database you want to fetch data from.", default=None)
|
||||
parser.add_argument("--table_ids", help="IDs of the Baserow tables you want to fetch data from, separated by commas.", default=None)
|
||||
parser.add_argument("--matrix", action="store_true", help="Merge tables based on references.")
|
||||
parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose mode for debugging.")
|
||||
parser.add_argument("--linked_fields", action="store_true", help="Outputs the linked tables")
|
||||
parser.add_argument("--output", choices=["linked_fields", "tables", "matrix"], default=[], nargs='+', help="Specify the type(s) of output: linked_fields, matrix, content or both")
|
||||
parser.add_argument("--quiet", action="store_true", help="Suppress output of json")
|
||||
return parser.parse_args()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user