#!/bin/env python import typer, json, os, sys from pathlib import Path from .config import Config from getpass import getpass from prettytable import PrettyTable import requests VERSION = "1.0" API_URI = "http://localhost:8080" app = typer.Typer() config = Config() config.load() @app.command() def version(): print(f"Version: {VERSION}") @app.command() def login(): username: str = input("Username: ") password: str = getpass("Password: ") result = requests.post(API_URI+"/api/login/", json={"username":username, "password":password}) data = result.json() table = PrettyTable() table.field_names = ["Status Code", "Message"] if result.status_code != 200: table.add_row([result.status_code, data["detail"]]) else: table.add_row([result.status_code, "success"]) config.set("token", data["access_token"]) config.save() print(table) if __name__ == "__main__": app()