mirror of
https://github.com/kevinveenbirkenbach/baserow-ifto.git
synced 2024-12-23 00:05:05 +01:00
implemented optional table_id and database_id
This commit is contained in:
parent
87a5e34b78
commit
ebea493d24
@ -33,7 +33,7 @@ def get_all_rows_from_table(base_url, api_key, table_id, verbose):
|
||||
next_url = f"{base_url}database/rows/table/{table_id}/"
|
||||
|
||||
while next_url:
|
||||
response = requests.get(next_url, headers=headers, verify=False)
|
||||
response = requests.get(next_url, headers=headers)
|
||||
if verbose:
|
||||
print("Headers:", headers)
|
||||
print("Requesting:", next_url)
|
||||
@ -49,7 +49,7 @@ def get_all_tables_from_database(base_url, api_key, database_id, verbose):
|
||||
if verbose:
|
||||
print(f"[INFO] Fetching all tables from database with ID: {database_id}...")
|
||||
headers = create_headers(api_key)
|
||||
response = requests.get(f"{base_url}database/tables/database/{database_id}/", headers=headers, verify=False)
|
||||
response = requests.get(f"{base_url}database/tables/database/{database_id}/", headers=headers)
|
||||
if verbose:
|
||||
print("Headers:", headers)
|
||||
return handle_api_response(response, verbose) or []
|
||||
@ -71,10 +71,19 @@ 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.")
|
||||
parser.add_argument("--database_id", help="ID of the Baserow database you want to fetch data from.", default=None)
|
||||
parser.add_argument("--table_id", help="ID of the Baserow table you want to fetch data from.", default=None)
|
||||
parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose mode for debugging.")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
all_data = get_all_data_from_database(args.base_url, args.api_key, args.database_id, args.verbose)
|
||||
print(all_data)
|
||||
if not args.database_id and not args.table_id:
|
||||
print("Error: Either database_id or table_id must be provided.")
|
||||
exit(1)
|
||||
|
||||
if args.table_id:
|
||||
table_data = get_all_rows_from_table(args.base_url, args.api_key, args.table_id, args.verbose)
|
||||
print(table_data)
|
||||
else:
|
||||
all_data = get_all_data_from_database(args.base_url, args.api_key, args.database_id, args.verbose)
|
||||
print(all_data)
|
||||
|
Loading…
Reference in New Issue
Block a user