diff --git a/__pycache__/baserow_api.cpython-311.pyc b/__pycache__/baserow_api.cpython-311.pyc new file mode 100644 index 0000000..fa1bda2 Binary files /dev/null and b/__pycache__/baserow_api.cpython-311.pyc differ diff --git a/fetch-all-data.py b/baserow_api.py similarity index 72% rename from fetch-all-data.py rename to baserow_api.py index 59b0aaa..d92e70e 100644 --- a/fetch-all-data.py +++ b/baserow_api.py @@ -1,5 +1,4 @@ import requests -import argparse import json class BaserowAPI: @@ -115,38 +114,4 @@ class BaserowAPI: if self.verbose: print("Merged Tables Data:", tables_data) - return tables_data - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Fetch all data from a Baserow database.") - parser.add_argument("base_url", help="Base URL of your Baserow instance, e.g., https://YOUR_BASEROW_INSTANCE_URL/api/") - 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("--quiet", action="store_true", help="Suppress output of json") - - args = parser.parse_args() - api = BaserowAPI(args.base_url, args.api_key, args.verbose) - - if not args.database_id and not args.table_ids: - print("Error: Either database_id or table_ids must be provided.") - exit(1) - - if args.table_ids: - table_ids = args.table_ids.split(',') - tables_data = {} - for table_id in table_ids: - table_data = api.get_all_rows_from_table(table_id.strip()) - tables_data[table_id] = table_data - - if args.matrix: - merged_data = api.merge_tables_on_reference(tables_data) - if not args.quiet: print(json.dumps(merged_data, indent=4)) - else: - if not args.quiet: print(json.dumps(tables_data, indent=4)) - else: - all_data = api.get_all_data_from_database(args.database_id) - if not args.quiet: print(json.dumps(all_data, indent=4)) + return tables_data \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..6e322ab --- /dev/null +++ b/main.py @@ -0,0 +1,37 @@ +import argparse +import json + +from baserow_api import BaserowAPI + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Fetch all data from a Baserow database.") + parser.add_argument("base_url", help="Base URL of your Baserow instance, e.g., https://YOUR_BASEROW_INSTANCE_URL/api/") + 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("--quiet", action="store_true", help="Suppress output of json") + + args = parser.parse_args() + api = BaserowAPI(args.base_url, args.api_key, args.verbose) + + if not args.database_id and not args.table_ids: + print("Error: Either database_id or table_ids must be provided.") + exit(1) + + if args.table_ids: + table_ids = args.table_ids.split(',') + tables_data = {} + for table_id in table_ids: + table_data = api.get_all_rows_from_table(table_id.strip()) + tables_data[table_id] = table_data + + if args.matrix: + merged_data = api.merge_tables_on_reference(tables_data) + if not args.quiet: print(json.dumps(merged_data, indent=4)) + else: + if not args.quiet: print(json.dumps(tables_data, indent=4)) + else: + all_data = api.get_all_data_from_database(args.database_id) + if not args.quiet: print(json.dumps(all_data, indent=4))