Skip to content

Instantly share code, notes, and snippets.

@xqm32
Last active November 17, 2023 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xqm32/5b549bc549fbbc9a398073ebb46c40e3 to your computer and use it in GitHub Desktop.
Save xqm32/5b549bc549fbbc9a398073ebb46c40e3 to your computer and use it in GitHub Desktop.
import json
from typing import Any, List
from httpx import Client
class CardSquare:
"""
https://webstatic.mihoyo.com/ys/event/bbs-lineup-qskp/index.html#/pc/publish
"""
def __init__(self, base_url: str = "https://api-takumi.mihoyo.com") -> None:
"""
- https://api-takumi.mihoyo.com
- https://sg-public-api.hoyolab.com
"""
self.client = Client(base_url=base_url, follow_redirects=True)
def roles(self) -> Any:
return self.client.get("/event/cardsquare/roles").json()
def role_skill(self, id: int) -> Any:
return self.client.get("/event/cardsquare/role/skill", params={"id": id}).json()
def actions(self, role_ids: List[int] = []) -> Any:
return self.client.post("/event/cardsquare/actions", json={"role_ids": role_ids}).json()
def action_skill(self, id: int) -> Any:
return self.client.get("event/cardsquare/action/skill", params={"id": id}).json()
def decode_card_code(self, code: str) -> Any:
return self.client.post(
"/event/cardsquare/decode_card_code",
json={"code": code},
).json()
def encode_card_code(self, action_cards: List[int], role_cards: List[int]) -> Any:
return self.client.post(
"/event/cardsquare/encode_card_code",
json={"action_cards": action_cards, "role_cards": role_cards},
).json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment