From 600a3824a65d8e867ef64214d1be8e38c05d3789 Mon Sep 17 00:00:00 2001 From: odrling Date: Thu, 6 Oct 2022 09:39:36 +0200 Subject: [PATCH] always show url --- hikari/hikari.py | 26 +++++++++++++++++++++----- setup.py | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/hikari/hikari.py b/hikari/hikari.py index 3cf74e8..04982de 100755 --- a/hikari/hikari.py +++ b/hikari/hikari.py @@ -2,18 +2,27 @@ import hashlib from dataclasses import dataclass from pathlib import Path -from pprint import pprint +from typing import Literal import pyperclip import requests import typer from requests_toolbelt import MultipartEncoder, MultipartEncoderMonitor +from rich.console import Console from rich.progress import (BarColumn, DownloadColumn, Progress, TextColumn, TimeRemainingColumn, TransferSpeedColumn) HIKARI_BASE = "https://hikari.butaishoujo.moe" HIKARI_URL = f"{HIKARI_BASE}/upload" +console = Console() + + +@dataclass +class UploadResponse: + status: Literal["exists"] | Literal["uploaded"] + url: str + def check_hash(filename: str, file: Path): h = hashlib.sha256() @@ -32,14 +41,21 @@ def check_hash(filename: str, file: Path): return req.raise_for_status() - return req.json() + return UploadResponse(**req.json()) -def output(copy: bool, resp: dict): +def output(copy: bool, resp: UploadResponse): if copy: - pyperclip.copy(resp['url']) + pyperclip.copy(resp.url) + action = "Copied" + elif resp.status == "exists": + action = "Found" + elif resp.status == "uploaded": + action = "Uploaded" else: - pprint(resp) + action = "" + + console.print(action, resp.url, style="bold green") @dataclass diff --git a/setup.py b/setup.py index 20271a0..dfb3810 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ with req.open() as f: setup( name='hikari', - version='1.3', + version='1.4', packages=find_packages(), include_package_data=True, install_requires=install_requires,