Akane710 commited on
Commit
2b8e58c
·
verified ·
1 Parent(s): 770a48f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +38 -1
main.py CHANGED
@@ -89,6 +89,25 @@ def upload_image(data, public_id=None):
89
  except Exception as e:
90
  raise Exception(f"Cloudinary upload error: {str(e)}")
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  # Utility to process images in card generation endpoints
93
  def process_images(result, player_id):
94
  characters = []
@@ -141,7 +160,7 @@ async def decrypt_and_upload(
141
  except Exception as e:
142
  return JSONResponse(content={"error": str(e)}, status_code=500)
143
 
144
- # Genshin Impact and Star Rail card/profile creation endpoints (Example for Genshin)
145
  @app.get("/genshin/{id}")
146
  async def genshin_characters(id: int, design: str = "1", character_id: int = None, character_art_url: str = None):
147
  try:
@@ -160,6 +179,24 @@ async def genshin_profile_route(id: int):
160
  except Exception as e:
161
  return JSONResponse(content={'error': str(e)}, status_code=500)
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  # Character AI message endpoint
164
  @app.get("/send_message")
165
  async def send_message(
 
89
  except Exception as e:
90
  raise Exception(f"Cloudinary upload error: {str(e)}")
91
 
92
+ # Helper functions to create genshin and starrail cards/profiles
93
+ async def genshin_card(id, designtype, character_id=None, character_art_url=None):
94
+ character_art = {str(character_id): character_art_url} if character_id and character_art_url else None
95
+ async with enkacard.ENC(uid=str(id), character_art=character_art) as encard:
96
+ return await encard.creat(akasha=True, template=(2 if str(designtype) == "2" else 1))
97
+
98
+ async def starrail_card(id, designtype, character_id=None, character_art_url=None):
99
+ character_art = {str(character_id): character_art_url} if character_id and character_art_url else None
100
+ async with starrailcard.Card(seeleland=True, remove_logo=True, character_art=character_art) as card:
101
+ return await card.create(id, style=(2 if str(designtype) == "2" else 1))
102
+
103
+ async def genshinprofile(id):
104
+ async with enkacard.ENC(uid=id) as encard:
105
+ return await encard.profile(card=True)
106
+
107
+ async def starrail_profile(id):
108
+ async with starrailcard.Card(remove_logo=True, seeleland=True) as card:
109
+ return await card.create_profile(id, style=2)
110
+
111
  # Utility to process images in card generation endpoints
112
  def process_images(result, player_id):
113
  characters = []
 
160
  except Exception as e:
161
  return JSONResponse(content={"error": str(e)}, status_code=500)
162
 
163
+ # Genshin Impact and Star Rail card/profile creation endpoints
164
  @app.get("/genshin/{id}")
165
  async def genshin_characters(id: int, design: str = "1", character_id: int = None, character_art_url: str = None):
166
  try:
 
179
  except Exception as e:
180
  return JSONResponse(content={'error': str(e)}, status_code=500)
181
 
182
+ @app.get("/starrail/{id}")
183
+ async def starrail_characters(id: int, design: str = "1", character_id: int = None, character_art_url: str = None):
184
+ try:
185
+ result = await starrail_card(id, design, character_id, character_art_url)
186
+ characters = process_images(result, id)
187
+ return JSONResponse(content={'response': characters})
188
+ except Exception as e:
189
+ return JSONResponse(content={'error': str(e)}, status_code=500)
190
+
191
+ @app.get("/starrail/profile/{id}")
192
+ async def starrail_profile_route(id: int):
193
+ try:
194
+ result = await starrail_profile(id)
195
+ profile_data = process_profile(result)
196
+ return JSONResponse(content={'response': profile_data})
197
+ except Exception as e:
198
+ return JSONResponse(content={'error': str(e)}, status_code=500)
199
+
200
  # Character AI message endpoint
201
  @app.get("/send_message")
202
  async def send_message(