2022-06-28 15:44:10 +00:00
|
|
|
from model.apihelper.hyperion import Hyperion
|
2022-04-14 07:18:45 +00:00
|
|
|
from service.cache import RedisCache
|
2022-06-09 07:12:06 +00:00
|
|
|
from service.repository import AsyncRepository
|
2022-04-14 07:18:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class GetGameInfo:
|
|
|
|
def __init__(self, repository: AsyncRepository, cache: RedisCache):
|
|
|
|
self.repository = repository
|
|
|
|
self.cache = cache
|
2022-06-01 03:46:26 +00:00
|
|
|
self.hyperion = Hyperion()
|
2022-04-14 07:18:45 +00:00
|
|
|
|
|
|
|
async def get_characters_cultivation_atlas(self, character_name: str) -> str:
|
|
|
|
qname = f"game:info:characters_cultivation_atlas:{character_name}"
|
|
|
|
url_info = await self.cache.get_str_list(qname)
|
|
|
|
if len(url_info) >= 1:
|
2022-05-27 09:07:51 +00:00
|
|
|
url = url_info[-1]
|
|
|
|
if url != "":
|
|
|
|
return url_info[-1]
|
2022-04-14 07:18:45 +00:00
|
|
|
|
|
|
|
async def get_post_id(collection_id: int) -> int:
|
2022-06-01 03:46:26 +00:00
|
|
|
post_full_in_collection = await self.hyperion.get_post_full_in_collection(collection_id)
|
2022-04-14 07:18:45 +00:00
|
|
|
if post_full_in_collection.error:
|
|
|
|
await self.cache.set_str_list(qname, [""], 3600)
|
|
|
|
return -1
|
|
|
|
_post_id: int = -1
|
|
|
|
for post_data in post_full_in_collection.data["posts"]:
|
|
|
|
topics = post_data["topics"]
|
|
|
|
for topic in topics:
|
|
|
|
if character_name == topic["name"]:
|
|
|
|
_post_id = int(post_data["post"]["post_id"])
|
|
|
|
break
|
|
|
|
if _post_id != -1:
|
|
|
|
break
|
|
|
|
return _post_id
|
|
|
|
|
2022-05-27 09:07:51 +00:00
|
|
|
post_id = await get_post_id(839176)
|
2022-04-14 07:18:45 +00:00
|
|
|
if post_id == -1:
|
2022-05-27 09:07:51 +00:00
|
|
|
post_id = await get_post_id(839179)
|
|
|
|
if post_id == -1:
|
|
|
|
post_id = await get_post_id(839181)
|
2022-04-14 07:18:45 +00:00
|
|
|
if post_id == -1:
|
|
|
|
await self.cache.set_str_list(qname, [""], 3600)
|
|
|
|
return ""
|
2022-06-01 03:46:26 +00:00
|
|
|
artwork_info = await self.hyperion.get_artwork_info(2, post_id)
|
2022-04-14 07:18:45 +00:00
|
|
|
await self.cache.set_str_list(qname, artwork_info.results.image_url_list, 3600)
|
|
|
|
return artwork_info.results.image_url_list[0]
|