add(app): create python application

This commit is contained in:
Aleksandr Tcitlionok
2024-12-11 12:14:25 +00:00
parent 11641e5e10
commit 24e09330ea
11 changed files with 531 additions and 2 deletions

36
cli/commands/export.py Normal file
View File

@@ -0,0 +1,36 @@
import click
import requests
BASE_URL = "http://localhost:8000/export" # Backend URL for exporting data
@click.command()
@click.option(
"--format",
type=click.Choice(["yaml", "json"], case_sensitive=False),
default="json",
help="Specify the export format: yaml or json. Default is json.",
)
@click.argument("output", required=False, type=click.Path(writable=True))
def export_data(format, output):
"""
Export Metal Check data in the specified format (yaml or json).
If an OUTPUT file is provided, the data will be saved to the file.
Otherwise, it will be printed to the console.
"""
try:
response = requests.get(f"{BASE_URL}?format={format}")
if response.status_code == 200:
data = response.text
if output:
with open(output, "w") as file:
file.write(data)
click.echo(f"Data successfully exported to {output}.")
else:
click.echo("\n📤 Exported Data:")
click.echo(data)
else:
click.echo(f"Error: {response.status_code} - {response.text}")
except requests.RequestException as e:
click.echo(f"Error: {e}")