From aff2241f2c94540119b3939d833501b441057a01 Mon Sep 17 00:00:00 2001 From: counterweight Date: Wed, 2 Aug 2023 20:09:28 +0200 Subject: [PATCH] Silly orders endpoint --- camisatoshi_wordpress_reports/cli.py | 5 +++-- camisatoshi_wordpress_reports/controllers.py | 22 +++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/camisatoshi_wordpress_reports/cli.py b/camisatoshi_wordpress_reports/cli.py index f17a2c4..f1877f1 100644 --- a/camisatoshi_wordpress_reports/cli.py +++ b/camisatoshi_wordpress_reports/cli.py @@ -11,5 +11,6 @@ def check_health(): @app.command() -def explode(): - print("Pew bam boom") +def show_orders(): + controllers.show_orders() + diff --git a/camisatoshi_wordpress_reports/controllers.py b/camisatoshi_wordpress_reports/controllers.py index 7e06880..073f941 100644 --- a/camisatoshi_wordpress_reports/controllers.py +++ b/camisatoshi_wordpress_reports/controllers.py @@ -6,19 +6,19 @@ from woocommerce import API API_CONFIG = dotenv_values( dotenv_path=Path.home() / Path(".camisatoshi-wordpress-reports/.env") ) +WC_API = API( + url=API_CONFIG["URL"], + consumer_key=API_CONFIG["CONSUMER_KEY"], + consumer_secret=API_CONFIG["CONSUMER_SECRET"], + version=API_CONFIG["VERSION"], +) def check_health(): print(f"Connecting to the configured woocomerce at {API_CONFIG['URL']}") - wc_api = API( - url=API_CONFIG["URL"], - consumer_key=API_CONFIG["CONSUMER_KEY"], - consumer_secret=API_CONFIG["CONSUMER_SECRET"], - version=API_CONFIG["VERSION"], - ) try: - api_reported_version = wc_api.get("").json()["namespace"] + api_reported_version = WC_API.get("").json()["namespace"] except: raise ConnectionError( "There was an issue connecting to the woocomerce API." @@ -28,3 +28,11 @@ def check_health(): print(f"Version reported by the API itself: {api_reported_version}") print("Connection successful. The API is reachable.") + + +def show_orders(): + print( + WC_API.get( + "orders", params={"after": "2023-07-21T18:02:23+00:00"} + ).json() + )