From 4caa037ab5843e5350fb639cb1bc8974556045fd Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Mon, 4 Sep 2023 13:48:30 +0200 Subject: [PATCH] Refactored file structure --- __pycache__/baserow_api.cpython-311.pyc | Bin 0 -> 7420 bytes fetch-all-data.py => baserow_api.py | 37 +----------------------- main.py | 37 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 36 deletions(-) create mode 100644 __pycache__/baserow_api.cpython-311.pyc rename fetch-all-data.py => baserow_api.py (72%) create mode 100644 main.py diff --git a/__pycache__/baserow_api.cpython-311.pyc b/__pycache__/baserow_api.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fa1bda2325655b5893c4d4a231ba6f725ffde37c GIT binary patch literal 7420 zcmb_hU2GFq7M`)k|2H_X35Jl8ArOKCIQ;*Fl;4mA+6GEWOVXxZ;~5eY#||?N(CI`% zRUfPs+NE10vT7^&q3Wh;rDfmxun(x+2OjoeCK@T$NUSQY_MvZHu`4084|~oX|I9d{ z+gp{BY1#%1usya-~;Lx{6GUj0BBGMf&^j)Po-p0%HKM9@!W8_rY=fCL2mf3 zs;;sslf-hGR2Ssfdd>~Gnqn|GV9buh-KPI4@J`N2S<{!A%_OJA_e|eSQM#I!#W-hj zvY5Rld4Y-KL*fS_qXs;r=c)dw{EXN?E#A!JZi-^=YDSs{no3XgUlM2Ya;A`%GNRl+ znJG-oT}`C(Gpn{m4PbP;GS>?E{%R%($|PprGyTbACYLEBlS;HP35i;v2i4gKNQ&esR5R)NJU|9#jLupoe87UktX+pMD}BOz<`P_j`%@P#uEL*| z#8g4#r^J*XN-}>fFY&Mpyd>V36Xk-OP`q#CVbHwNnwp)>X40ubCZFrSF6VP`m)UZ1 zt}q32pwLo|3jrV57I7_D#UICCSqk_DIR%)(EQ<=%COl5;@G-oWKRr=jzJ(pE1%YuWn150626rSl958sIO9 zX)$wC6nNR{MMWwR{+g7Z;j0#kvJy5$3$sy`Ye+`;u>{1n^I59(Xj;I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)*d!br`>(*x*G+Ftb-F*
Oh33JB3XE-(Ec7MVS3-ebGH}P{ zO6)e>82%#ys^@~|!9gLDF2IH3>@nrE%_Yph2t~_P$jN*T4*1oPB?hzkbSf(!OEh}g zKF5K#jIrDuM%y}MJ>R%Xql;@lAA9Jo7g1nK1JEw+mX5+p+KXfx5Esq4jG_stqoOAX*rh@#M`j4L$IX}tiA|+ z!2AI-iObpAya)noZC8I-qp}~l?zX{lxJ<49SDL0jo5@Y%S-uN zS!c`f!*IF#2A+)vB%EEdtu`FXVjvDzww{@}DhdLkq;5NK0Y@V>=uJn;D?vU}-BWob zil~Cwri^84((U1z>B$tt8Ck*@JWi^izlFdg@-<1uS}!XXqB>bKO0CQES{bw5R@2xK zsqsnZ8q8p$ff=NoXwYXy8zZR?RL0w4FxPsrjvE_Z2q0zaPqF69z*YVZZij5a;8A+y zKBAKWgA8b70B*9^ODr1g#MJUcZfPQ?Ps|zm;)#tUYnZ++K*9NApn zcC`4)LQp4LG_s{C!xcD9-iBMfQ9 zi%d3fkPf$ZaidNS803IP4wSX(Y}L$3yrt4W1v8Ni&#C&g6x;EPj(@^2S^$ zYt=|0SbHl7#8WOkph)znvJbOp{?cnm(0y8t6o1~3aATkZKjiyB?$rM(F1M!(7TQ6A z9uNHNQ73D{9=PPJlkSLTZH1|m?LN<8SdSWsgs`?wI((iRxLgey;XSa5D~Y8rstBH+ z2Dup3TFN^I^xQvaP0%svb!dV=s>q{2DsGl#%S`wV{VOw}JM^!@-C$V|xjOv^E&t~W IYN=BH0qQ#WXaE2J literal 0 HcmV?d00001 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))