Skip to content

Commit

Permalink
2.1.9
Browse files Browse the repository at this point in the history
Added:

* EnkaApi support - Now you can receive data from Enka and not from MiHoMo.
* Added the ability to set your own color settings for the character. (https://github.com/DEViantUA/StarRailCard/blob/main/Examples/color.py)

In the future we plan to add:
* Support for converting Enka.py data from Seria to generate cards.
* Full API wrapper for both postals


Signed-off-by: Deviant <[email protected]>
  • Loading branch information
DEViantUA committed May 17, 2024
1 parent a6ec639 commit 67815e5
Show file tree
Hide file tree
Showing 16 changed files with 633 additions and 531 deletions.
2 changes: 1 addition & 1 deletion starrailcard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

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

Expand Down
24 changes: 18 additions & 6 deletions starrailcard/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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,
cache = {"maxsize": 150, "ttl": 300}, enka: bool = False, api_data: api_mihomo.MiHoMoApi = None, proxy: str = None,
user_agent: str = None):
user_agent: str = None, color: dict = None):
"""Main class for generating cards
Args:
Expand All @@ -34,6 +34,7 @@ def __init__(self, lang: str = "en", character_art = None, character_id = None,
api_data (MiHoMoApi, optional): Pass your data received via: api.ApiMiHoMo(uid,"en").get()
proxy (str, optional): Proxy as a string: http://111.111.111.111:8888
user_agent (str, optional): Custom User-Agent.
color: (dict), Dictionary: {"character_id_1": (255,255,255,255), "character_id_2": (0,0,0,255),...}.
"""
self.lang = lang
self.character_art = character_art
Expand All @@ -49,6 +50,7 @@ def __init__(self, lang: str = "en", character_art = None, character_id = None,
self.api_data = api_data
self.proxy = proxy
self.user_agent = options.get_user_agent(user_agent)
self.color = color


async def __aenter__(self):
Expand Down Expand Up @@ -80,6 +82,9 @@ async def __aenter__(self):
image_control._boost_speed = self.boost_speed


if isinstance(self.color, dict):
self.color = await options.get_color_user(self.color)

if self.remove_logo:
print("""
Thank you for using our StarRailCard!
Expand Down Expand Up @@ -123,7 +128,7 @@ async def create_profile(self, uid: Union[int,str], style: bool = 1, hide_uid: b
"""Function for generating a user profile card
Args:
uid (int): UID of the user in the game.
uid (Union[int,str]): UID of the user in the game.
style (int, optional): Card style. Defaults to 1.
hide_uid (bool, optional): Hide UID. Defaults to False.
background (str, optional): Link to custom card background. Defaults to None.
Expand All @@ -137,6 +142,7 @@ async def create_profile(self, uid: Union[int,str], style: bool = 1, hide_uid: b
try:
data = await enka.ApiEnkaNetwork(uid, lang= self.lang).get()
except Exception as e:
print(e)
print("To use the EnkaNetwork API you need to download/update the asset\nExample: await enka.ApiEnkaNetwork().update_assets()")
data = await api.ApiMiHoMo(uid, lang= self.lang, force_update = force_update, user_agent= self.user_agent).get()
else:
Expand Down Expand Up @@ -179,7 +185,7 @@ async def create_profile(self, uid: Union[int,str], style: bool = 1, hide_uid: b

return StarRailCard.StarRail(**response)

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):
async def create(self, uid: Union[int,str], style: int = 1, hide_uid: bool = False, force_update: bool = False, style_settings = None, log: bool = False):
"""Function for generating character cards
Args:
Expand All @@ -198,6 +204,7 @@ async def create(self, uid: Union[int,str], style: bool = 1, hide_uid: bool = Fa
try:
data = await enka.ApiEnkaNetwork(uid, lang= self.lang).get()
except Exception as e:
print(e)
print("To use the EnkaNetwork API you need to download/update the asset")
data = await api.ApiMiHoMo(uid, lang= self.lang, force_update = force_update, user_agent= self.user_agent).get()
else:
Expand Down Expand Up @@ -241,16 +248,21 @@ async def get_result(key):
if not str(key.id) in self.character_id:
return

if self.color:
color = self.color.get(str(key.id))
else:
color = None

art = None
if self.character_art:
if str(key.id) in self.character_art:
art = self.character_art[str(key.id)]
if style == 1:
result.append(await style_relict_score.Create(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, color).start())
elif style == 2:
result.append(await style_ticket.Create(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, color).start())
elif style == 3:
result.append(await style_card.Create(key,self.translateLang,art,hide_uid,uid, self.seeleland,self.remove_logo).start())
result.append(await style_card.Create(key,self.translateLang,art,hide_uid,uid, self.seeleland,self.remove_logo, color).start())
except Exception as e:
print(f"Error in get_result for character {key.id}: {e}")

Expand Down
2 changes: 0 additions & 2 deletions starrailcard/src/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from ..tools import http, translator, ukrainization, options
from ..model import api_mihomo
from .error import StarRailCardError
from ..tools.json_data import JsonManager
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 Down
60 changes: 22 additions & 38 deletions starrailcard/src/api/enka.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,25 @@
from ..model import api_mihomo

_API_ENKA = "https://enka.network/api/hsr/uid/{uid}"
_ASSETS_ENKA = "https://raw.githubusercontent.com/EnkaNetwork/API-docs/master/store/hsr/{asset}.json"
_INDEX_MIHOMO = "https://raw.githubusercontent.com/Mar-7th/StarRailRes/master/index_new/{lang}/{index}.json"

_ASSET_NAME = [
_INDEX_NAME = [
"avatars",
"character_promotions",
"character_ranks",
"character_skill_trees",
"character_skills",
"characters",
"meta",
"ranks",
"relics",
"skills",
"skilltree",
"weps",
"hsr"
]

_INDEX_NAME = [
"paths",
"elements",
"character_skills",
"character_skill_trees",
"properties",
"light_cone_promotions",
"light_cone_ranks",
"relics",
"light_cones",
"paths",
"properties",
"relic_main_affixes",
"relic_sub_affixes",
"relic_sets",
"character_ranks"
"relic_sub_affixes",
"relics"
]


Expand All @@ -62,7 +54,8 @@ async def get(self):

if self.parsed:
data = await AssetEnkaParsed(data).collect()

else:
return data
except aiohttp.ClientConnectionError:
raise StarRailCardError(1, "Server is not responding")
except aiohttp.ClientResponseError as e:
Expand All @@ -71,31 +64,22 @@ async def get(self):
if self.ua_lang:
await ukrainization.TranslateDataManager().load_translate_data()

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

async def update_assets(self):
print("===START UPDATE INDEX===")
async def update_assets(self, lang = None):
print("===START UPDATE ASSET===")
for name in _INDEX_NAME:
for lang in SUPPORTED_LANGUAGES:
if lang == "ua":
for langs in SUPPORTED_LANGUAGES:
if langs == "ua":
continue
if not lang is None:
if langs != lang:
continue
data = await http.AioSession.get(_INDEX_MIHOMO.format(lang = lang, index=name))
if not os.path.exists(PathData.ENKA_INDEX.value / lang):
os.makedirs(PathData.ENKA_INDEX.value / lang)
await JsonManager(PathData.ENKA_INDEX.value / lang /f"{name}.json").write(data)

print(f"- Updated file: {name}")
print("===END UPDATE INDEX===")
print()
print("===START UPDATE ASSETS===")
for name in _ASSET_NAME:
if name == "hsr":
data = await http.AioSession.get(_ASSETS_ENKA.format(asset=name))
else:
data = await http.AioSession.get(_ASSETS_ENKA.format(asset=f"honker_{name}"))
await JsonManager(PathData.ENKA.value / f"{name}.json").write(data)
print(f"- Updated file: {name}")

print("===END UPDATE ASSETS===")

print("===END UPDATE ASSET===")

Loading

0 comments on commit 67815e5

Please sign in to comment.