Skip to content

Commit

Permalink
update hub
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Jun 11, 2024
1 parent 9df0f5f commit f28fb46
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions apsbot/acc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,35 @@
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)
result = bim360.get_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()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="apsbot",
version="0.2.3",
version="0.2.4",
packages=find_packages(),
include_package_data=True,
install_requires=[
Expand Down

0 comments on commit f28fb46

Please sign in to comment.