mirror of
https://github.com/kevinveenbirkenbach/baserow-ifto.git
synced 2024-11-22 19:01:05 +01:00
Refactored file structure
This commit is contained in:
parent
4216679c17
commit
4caa037ab5
BIN
__pycache__/baserow_api.cpython-311.pyc
Normal file
BIN
__pycache__/baserow_api.cpython-311.pyc
Normal file
Binary file not shown.
@ -1,5 +1,4 @@
|
|||||||
import requests
|
import requests
|
||||||
import argparse
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
class BaserowAPI:
|
class BaserowAPI:
|
||||||
@ -116,37 +115,3 @@ class BaserowAPI:
|
|||||||
if self.verbose:
|
if self.verbose:
|
||||||
print("Merged Tables Data:", tables_data)
|
print("Merged Tables Data:", tables_data)
|
||||||
return 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))
|
|
37
main.py
Normal file
37
main.py
Normal file
@ -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))
|
Loading…
Reference in New Issue
Block a user