Skip to content

Commit

Permalink
Bump pypi version
Browse files Browse the repository at this point in the history
  • Loading branch information
thesadru committed Dec 25, 2021
1 parent f6a79b9 commit d5722e7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
45 changes: 44 additions & 1 deletion genshin/__main__.py
Original file line number Diff line number Diff line change
@@ -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")


Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion genshin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="genshin",
version="0.2.0",
version="0.3.0",
author="thesadru",
author_email="[email protected]",
description="An API wrapper for Genshin Impact.",
Expand Down

0 comments on commit d5722e7

Please sign in to comment.