Update main.py
Browse files
main.py
CHANGED
|
@@ -31,13 +31,22 @@ async def genshin_card(id, designtype,character_id=None, character_art_url=None)
|
|
| 31 |
async with encbanner.ENC(uid=str(id), character_art=character_art) as encard:
|
| 32 |
return await encard.creat(akasha=True, template=(2 if str(designtype) == "2" else 1))
|
| 33 |
|
| 34 |
-
# Star Rail card creation with optional character ID
|
| 35 |
-
async def starrail_card(id, designtype, character_id=None, character_art_url=None):
|
| 36 |
-
# Use the provided character ID and character art URL from user input, if available
|
| 37 |
character_art = {str(character_id): character_art_url} if character_id and character_art_url else None
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
# Star Rail profile creation
|
|
@@ -69,17 +78,24 @@ async def genshin_characters(id: int, design: str = "1", character_id: int = Non
|
|
| 69 |
|
| 70 |
# Route for Star Rail with optional character ID
|
| 71 |
@app.get("/starrail/{id}")
|
| 72 |
-
async def starrail_characters(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
try:
|
| 74 |
-
# Call starrail_card
|
| 75 |
-
result = await starrail_card(id, design, character_id, character_art_url)
|
| 76 |
characters = process_images(result, id)
|
| 77 |
return JSONResponse(content={'response': characters})
|
| 78 |
|
| 79 |
except Exception as e:
|
| 80 |
return JSONResponse(content={'error': 'UNKNOWN ERR: ' + str(e)}, status_code=500)
|
| 81 |
|
| 82 |
-
|
| 83 |
# Route for Star Rail profile
|
| 84 |
@app.get("/starrail/profile/{id}")
|
| 85 |
async def starrail_profile_route(id: int):
|
|
|
|
| 31 |
async with encbanner.ENC(uid=str(id), character_art=character_art) as encard:
|
| 32 |
return await encard.creat(akasha=True, template=(2 if str(designtype) == "2" else 1))
|
| 33 |
|
| 34 |
+
# Star Rail card creation with optional character ID and cookies
|
| 35 |
+
async def starrail_card(id, designtype, character_id=None, character_art_url=None, ltmid_v2=None, ltoken_v2=None, ltuid_v2=None):
|
|
|
|
| 36 |
character_art = {str(character_id): character_art_url} if character_id and character_art_url else None
|
| 37 |
+
# Use cookies if provided
|
| 38 |
+
if ltmid_v2 and ltoken_v2 and ltuid_v2:
|
| 39 |
+
cookie = {
|
| 40 |
+
"ltmid_v2": ltmid_v2,
|
| 41 |
+
"ltoken_v2": ltoken_v2,
|
| 42 |
+
"ltuid_v2": ltuid_v2
|
| 43 |
+
}
|
| 44 |
+
async with starrailcard.HoYoCard(cookie=cookie) as card:
|
| 45 |
+
return await card.create(id, style=(2 if str(designtype) == "2" else 1))
|
| 46 |
+
else:
|
| 47 |
+
# Fallback to the existing process
|
| 48 |
+
async with starrailcard.Card(seeleland=True, remove_logo=True, character_art=character_art, enka=True) as card:
|
| 49 |
+
return await card.create(id, style=(2 if str(designtype) == "2" else 1))
|
| 50 |
|
| 51 |
|
| 52 |
# Star Rail profile creation
|
|
|
|
| 78 |
|
| 79 |
# Route for Star Rail with optional character ID
|
| 80 |
@app.get("/starrail/{id}")
|
| 81 |
+
async def starrail_characters(
|
| 82 |
+
id: int,
|
| 83 |
+
design: str = "1",
|
| 84 |
+
character_id: int = None,
|
| 85 |
+
character_art_url: str = None,
|
| 86 |
+
ltmid_v2: str = None,
|
| 87 |
+
ltoken_v2: str = None,
|
| 88 |
+
ltuid_v2: str = None
|
| 89 |
+
):
|
| 90 |
try:
|
| 91 |
+
# Call starrail_card with cookies if provided
|
| 92 |
+
result = await starrail_card(id, design, character_id, character_art_url, ltmid_v2, ltoken_v2, ltuid_v2)
|
| 93 |
characters = process_images(result, id)
|
| 94 |
return JSONResponse(content={'response': characters})
|
| 95 |
|
| 96 |
except Exception as e:
|
| 97 |
return JSONResponse(content={'error': 'UNKNOWN ERR: ' + str(e)}, status_code=500)
|
| 98 |
|
|
|
|
| 99 |
# Route for Star Rail profile
|
| 100 |
@app.get("/starrail/profile/{id}")
|
| 101 |
async def starrail_profile_route(id: int):
|