From 316343c6c2cfd8a5f9b41165b8390a122f9cf105 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 3 Sep 2023 20:12:18 +0200 Subject: [PATCH] Added fetch-all-data.py --- fetch-all-data.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 fetch-all-data.py diff --git a/fetch-all-data.py b/fetch-all-data.py new file mode 100644 index 0000000..1075744 --- /dev/null +++ b/fetch-all-data.py @@ -0,0 +1,40 @@ +import requests + +BASE_URL = "https://YOUR_BASEROW_INSTANCE_URL/api/" +API_KEY = "YOUR_API_KEY" +HEADERS = { + "Authorization": f"Token {API_KEY}", + "Content-Type": "application/json" +} + +def get_all_rows_from_table(table_id): + rows = [] + next_url = f"{BASE_URL}database/rows/table/{table_id}/" + + while next_url: + response = requests.get(next_url, headers=HEADERS) + data = response.json() + rows.extend(data['results']) + next_url = data['next'] + + return rows + +def get_all_tables_from_database(database_id): + response = requests.get(f"{BASE_URL}database/tables/database/{database_id}/", headers=HEADERS) + tables = response.json() + return tables + +def get_all_data_from_database(database_id): + tables = get_all_tables_from_database(database_id) + data = {} + + for table in tables: + table_id = table['id'] + table_name = table['name'] + data[table_name] = get_all_rows_from_table(table_id) + + return data + +database_id = "YOUR_DATABASE_ID" +all_data = get_all_data_from_database(database_id) +print(all_data)