From f28fb46e0bcc32202d43bbaaa72acf4e362ce9a8 Mon Sep 17 00:00:00 2001 From: Chuong Ho <31106432+chuongmep@users.noreply.github.com> Date: Tue, 11 Jun 2024 20:03:47 +0800 Subject: [PATCH] update hub --- apsbot/acc.py | 23 ++++++++++++++++++++--- setup.py | 2 +- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/apsbot/acc.py b/apsbot/acc.py index 0c0d503..7ff247d 100644 --- a/apsbot/acc.py +++ b/apsbot/acc.py @@ -5,10 +5,11 @@ from .tokenconfig import TokenConfig from tabulate import tabulate import os - +import pandas as pd @click.command() -def hubs(): +@click.option('--save_data', prompt='Save Data(y/n)', default='n', help='Save data to file.') +def hubs(save_data): """This command lists all hubs.""" token = TokenConfig.load_config() bim360 = BIM360(token) @@ -16,7 +17,23 @@ def hubs(): if not result: click.echo("No hubs found.") return - print(json.dumps(result, indent=4)) + if str.lower(save_data) == 'y': + folder = Config.load_folder_path() + file_path = os.path.join(folder, 'hubs.json') + with open(file_path, 'w') as f: + json.dump(result, f, indent=4) + click.echo(f"Hubs data saved to {file_path}") + # get hubids and names show dataframe from result json + df = pd.DataFrame() + for hub in result["data"]: + if hub["type"] =="hubs": + id = hub["id"] + name = hub["attributes"]["name"] + region = hub["attributes"]["region"] + type = hub["attributes"]["extension"]["type"] + df = pd.concat([df, pd.DataFrame({"id": [id], "name": [name], "region": [region], "type": [type]})]) + print(tabulate(df, headers="keys", tablefmt="psql")) + @click.command() diff --git a/setup.py b/setup.py index 9d942ef..08c70a5 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="apsbot", - version="0.2.3", + version="0.2.4", packages=find_packages(), include_package_data=True, install_requires=[