From d5722e7096136828f489b249da62d30e6b1c29ce Mon Sep 17 00:00:00 2001 From: sadru Date: Sat, 25 Dec 2021 22:58:55 +0100 Subject: [PATCH] Bump pypi version --- genshin/__main__.py | 45 ++++++++++++++++++++++++++++++++++++++++++++- genshin/client.py | 2 +- setup.py | 2 +- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/genshin/__main__.py b/genshin/__main__.py index f70be867..6b53137b 100644 --- a/genshin/__main__.py +++ b/genshin/__main__.py @@ -1,12 +1,16 @@ """A cli for genshin.py""" import asyncio from functools import update_wrapper -from typing import Any, Awaitable, Callable +from typing import Any, Awaitable, Callable, Dict, List, Optional, Tuple, TypeVar +import difflib import typer +import click import genshin +T = TypeVar("T", bound=Any) + app = typer.Typer(name="genshin") @@ -199,5 +203,44 @@ async def pity(): typer.secho(f"Never pulled a 5*. At most {a} pulls left until pity") +@app.command() +@asynchronous +async def calculate(): + """Calcualte the amount of resources needed to upgrade anything""" + async with genshin.GenshinClient() as client: + client.set_browser_cookies() + + characters = await client.get_calculator_characters() + + inp: Any = typer.prompt(f"Character (name or id)") + + names = {obj.name: obj for obj in characters} + matches = difflib.get_close_matches(inp, names, n=1) + if matches: + character = names[matches[0]] + elif not inp.isdigit(): + raise click.ClickException("Invalid character name") + else: + inp = int(inp) + for character in characters: + if character.id == inp: + break + + raise click.ClickException("Invalid character format") + + c: Any = ( + character.id, + typer.prompt("Current level", type=int), + typer.prompt("Target level", type=int), + ) + result = await client.calculate(c) + + typer.echo() + typer.echo(f"Items needed to level up {character.name} from lvl {c[1]} to {c[2]}:") + + for item in result.total: + typer.echo(f"{item.amount}x {item.name}") + + if __name__ == "__main__": app() diff --git a/genshin/client.py b/genshin/client.py index 7610af45..55fecde1 100644 --- a/genshin/client.py +++ b/genshin/client.py @@ -1531,7 +1531,7 @@ class ChineseClient(GenshinClient): ACT_ID = "e202009291139501" TAKUMI_URL = "https://api-takumi.mihoyo.com/" - RECORD_URL = "https://api-takumi.mihoyo.com/game_record/app/" + RECORD_URL = "https://api-takumi-record.mihoyo.com/game_record/app/" INFO_LEDGER_URL = "https://hk4e-api.mihoyo.com/event/ys_ledger/monthInfo" DETAIL_LEDGER_URL = "https://hk4e-api.mihoyo.com/event/ys_ledger/monthDetail" REWARD_URL = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/" diff --git a/setup.py b/setup.py index 5fe21730..841d9029 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="genshin", - version="0.2.0", + version="0.3.0", author="thesadru", author_email="thesadru@gmail.com", description="An API wrapper for Genshin Impact.",