Skip to content

Commit

Permalink
2.1.8
Browse files Browse the repository at this point in the history
Signed-off-by: Deviant <112615715+DEViantUA@users.noreply.github.com>
  • Loading branch information
DEViantUA authored May 11, 2024
1 parent 48cc9ef commit d99a703
Show file tree
Hide file tree
Showing 25 changed files with 1,907 additions and 303 deletions.
5 changes: 3 additions & 2 deletions starrailcard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@

__title__ = 'StarRailCard.py'
__author__ = 'DeviantUa'
__version__ = '2.1.6'
__version__ = '2.1.8'
__license__ = 'MIT'
__copyright__ = 'Copyright 2024-present DeviantUa'

from .client import *
from .utils import *
from .src.tools.enums import *
from .src.tools.enums import *

36 changes: 19 additions & 17 deletions starrailcard/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
# All rights reserved.

import anyio
from typing import Union
#import asyncio

from .src.tools import http, ukrainization, options, translator, cashe, git
from .src.generator import style_relict_score, style_ticket, style_profile_phone
from .src.tools import cache, http, ukrainization, options, translator, git
from .src.generator import style_relict_score, style_ticket, style_profile_phone, style_card
from .src.api import api, enka
from .src.model import StarRailCard,api_mihomo
from .src.tools.pill import image_controle
from .src.tools.pill import image_control



class Card:
def __init__(self, lang: str = "en", character_art = None, character_id = None, seeleland: bool = False,
user_font = None, save: bool = False, asset_save: bool = False, boost_speed: bool = False, remove_logo: bool = False,
cashe = {"maxsize": 150, "ttl": 300}, enka: bool = False, api_data: api_mihomo.MiHoMoApi = None, proxy: str = None,
cache = {"maxsize": 150, "ttl": 300}, enka: bool = False, api_data: api_mihomo.MiHoMoApi = None, proxy: str = None,
user_agent: str = None):
"""Main class for generating cards
Expand All @@ -42,7 +43,7 @@ def __init__(self, lang: str = "en", character_art = None, character_id = None,
self.save = save
self.asset_save = asset_save
self.remove_logo = remove_logo
self.cashe = cashe
self.cache = cache
self.enka = enka
self.boost_speed = boost_speed
self.api_data = api_data
Expand All @@ -51,10 +52,10 @@ def __init__(self, lang: str = "en", character_art = None, character_id = None,


async def __aenter__(self):
cashe.Cache.get_cache(maxsize = self.cashe.get("maxsize", 150), ttl = self.cashe.get("ttl", 300))
cache.Cache.get_cache(maxsize = self.cache.get("maxsize", 150), ttl = self.cache.get("ttl", 300))
await http.AioSession.enter(self.proxy)

await git.ImageCache.set_assets_dowload(self.asset_save)
await git.ImageCache.set_assets_download(self.asset_save)

if self.character_id:
self.character_id = await options.get_charter_id(self.character_id)
Expand All @@ -65,7 +66,6 @@ async def __aenter__(self):
else:
self.character_art = await options.get_character_art(self.character_art)


if not self.lang in translator.SUPPORTED_LANGUAGES:
self.lang = "en"

Expand All @@ -77,7 +77,7 @@ async def __aenter__(self):
if self.user_font:
await git.change_font(font_path = self.user_font)

image_controle._boost_speed = self.boost_speed
image_control._boost_speed = self.boost_speed


if self.remove_logo:
Expand Down Expand Up @@ -111,15 +111,15 @@ async def set_lang(self, lang):

self.translateLang = translator.Translator(lang)

async def set_user_font(self, user_font):
async def set_user_font(self, user_font: str):
"""Will install a custom font
Args:
user_font (srt): Font path or font name.
"""
await git.change_font(font_path = user_font)
async def creat_profile(self, uid, style = 1, hide_uid = False, background = None, force_update = False):

async def create_profile(self, uid: Union[int,str], style: bool = 1, hide_uid: bool = False, background = None, force_update: bool = False):
"""Function for generating a user profile card
Args:
Expand Down Expand Up @@ -168,7 +168,7 @@ async def creat_profile(self, uid, style = 1, hide_uid = False, background = Non
style = 1

if style == 1:
response["card"] = await style_profile_phone.Creat(data,self.translateLang,self.character_art,hide_uid,uid,background, self.remove_logo).start()
response["card"] = await style_profile_phone.Create(data,self.translateLang,self.character_art,hide_uid,uid,background, self.remove_logo).start()

for key in data.characters:
response["character_id"].append(key.id)
Expand All @@ -179,7 +179,7 @@ async def creat_profile(self, uid, style = 1, hide_uid = False, background = Non

return StarRailCard.StarRail(**response)

async def creat(self, uid, style = 1, hide_uid = False, force_update = False, style_settings = None):
async def create(self, uid: Union[int,str], style: bool = 1, hide_uid: bool = False, force_update: bool = False, style_settings = None, log: bool = False):
"""Function for generating character cards
Args:
Expand Down Expand Up @@ -208,7 +208,7 @@ async def creat(self, uid, style = 1, hide_uid = False, force_update = False, st
result = []

style, style_settings = await options.style_setting(style, style_settings)

try:
player = data.player.model_dump()
except:
Expand Down Expand Up @@ -246,9 +246,11 @@ async def get_result(key):
if str(key.id) in self.character_art:
art = self.character_art[str(key.id)]
if style == 1:
result.append(await style_relict_score.Creat(key,self.translateLang,art,hide_uid,uid, self.seeleland,self.remove_logo).start())
result.append(await style_relict_score.Create(key,self.translateLang,art,hide_uid,uid, self.seeleland,self.remove_logo).start())
elif style == 2:
result.append(await style_ticket.Creat(key,self.translateLang,art,hide_uid,uid, self.seeleland,self.remove_logo).start())
result.append(await style_ticket.Create(key,self.translateLang,art,hide_uid,uid, self.seeleland,self.remove_logo).start())
elif style == 3:
result.append(await style_card.Create(key,self.translateLang,art,hide_uid,uid, self.seeleland,self.remove_logo).start())
except Exception as e:
print(f"Error in get_result for character {key.id}: {e}")

Expand Down
25 changes: 23 additions & 2 deletions starrailcard/src/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ..tools.enums import PathData

_API_MIHOMO: str = "https://api.mihomo.me/sr_info_parsed/{uid}"
_API_MIHOMO_NAKED: str = "https://api.mihomo.me/sr_info/{uid}"



Expand All @@ -29,6 +30,10 @@ def __init__(self, uid: str, lang: str = "en", v: int = 2, force_update: bool =

self.v = v

async def recollect(self, data):

pass

async def get(self) -> Optional[api_mihomo.MiHoMoApi]:
"""Get data from the MiHoMo API."""
try:
Expand All @@ -41,7 +46,6 @@ async def get(self) -> Optional[api_mihomo.MiHoMoApi]:
headers = {
"User-Agent": self.user_agent
}

data = await http.AioSession.get(_API_MIHOMO.format(uid=self.uid), headers = headers, params=params, proxy= self.proxy)

if data is None:
Expand All @@ -63,7 +67,24 @@ async def get(self) -> Optional[api_mihomo.MiHoMoApi]:
except aiohttp.ClientResponseError as e:
raise StarRailCardError(e.status, f"Server returned status code {e.status}")

if data["player"]["space_info"].get("book_count") is None:
self.dop_info = await http.AioSession.get(_API_MIHOMO_NAKED.format(uid=self.uid), headers = headers, params=params, proxy= self.proxy)
data = await self.add_info(data)

if self.ua_lang:
await ukrainization.TranslateDataManager().load_translate_data()

return api_mihomo.MiHoMoApi(player=data["player"], characters=data["characters"], dont_update_link= False)
return api_mihomo.MiHoMoApi(player=data["player"], characters=data["characters"], dont_update_link= False)

async def add_info(self, data):
info = self.dop_info["detailInfo"]["recordInfo"]

data["player"]["space_info"]["relicCount"] = info.get("relicCount", 0)
data["player"]["space_info"]["musicCount"] = info.get("musicCount", 0)
data["player"]["space_info"]["bookCount"] = info.get("bookCount", 0)

memory_data = info.get("challengeInfo", {})
data["player"]["space_info"]["memory_data"]["abyssStarCount"] = memory_data.get("abyssStarCount")
data["player"]["space_info"]["memory_data"]["abyssLevel"] = memory_data.get("abyssLevel")

return data
Loading

0 comments on commit d99a703

Please sign in to comment.