Update main.py
Browse files
main.py
CHANGED
@@ -88,7 +88,6 @@
|
|
88 |
|
89 |
# if __name__ == "__main__":
|
90 |
# app.run(debug=False, use_reloader=False)
|
91 |
-
|
92 |
import enkacard
|
93 |
import enkacard.encbanner
|
94 |
import enkanetwork
|
@@ -102,11 +101,18 @@ import base64
|
|
102 |
|
103 |
enka_update = EnkaNetworkAPI()
|
104 |
|
|
|
|
|
105 |
async def update_genshin():
|
106 |
async with enka_update:
|
107 |
await enka_update.update_assets(lang=["EN"], path="/tmp")
|
108 |
|
109 |
-
app
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
async def card(id, designtype):
|
112 |
async with enkacard.encbanner.ENC(uid=str(id)) as encard:
|
@@ -123,7 +129,7 @@ def characters(id):
|
|
123 |
dt.card.save(byte_io, "PNG")
|
124 |
byte_io.seek(0)
|
125 |
image_url = upload_image(byte_io)
|
126 |
-
|
127 |
characters.append({
|
128 |
"name": dt.name,
|
129 |
"url": image_url
|
@@ -158,31 +164,14 @@ def upload_image(data):
|
|
158 |
|
159 |
Parameters:
|
160 |
- data: A BytesIO object containing the image data.
|
161 |
-
|
162 |
Returns:
|
163 |
- A base64-encoded string of the image.
|
164 |
"""
|
165 |
# Convert the image data to a base64-encoded string
|
166 |
image_base64 = base64.b64encode(data.getvalue()).decode('utf-8')
|
167 |
-
|
168 |
# Return the base64-encoded string
|
169 |
return image_base64
|
170 |
-
# def upload_image(data):
|
171 |
-
# url = "https://telegra.ph/upload"
|
172 |
-
# files = {'file': ('file', data, "image/png")}
|
173 |
-
# response = requests.post(url, files=files)
|
174 |
-
|
175 |
-
# if response.status_code != 200:
|
176 |
-
# raise Exception(f"HTTP Error: {response.status_code}")
|
177 |
-
|
178 |
-
# try:
|
179 |
-
# body = response.json()
|
180 |
-
# if isinstance(body, list) and 'src' in body[0]:
|
181 |
-
# return "https://telegra.ph" + body[0]['src']
|
182 |
-
# else:
|
183 |
-
# raise Exception(f"Telegraph error: {body.get('error', 'Unknown error')}")
|
184 |
-
# except (ValueError, KeyError, IndexError) as e:
|
185 |
-
# raise Exception(f"Failed to parse response: {str(e)}")
|
186 |
|
187 |
if __name__ == "__main__":
|
188 |
app.run(debug=False, use_reloader=False)
|
|
|
88 |
|
89 |
# if __name__ == "__main__":
|
90 |
# app.run(debug=False, use_reloader=False)
|
|
|
91 |
import enkacard
|
92 |
import enkacard.encbanner
|
93 |
import enkanetwork
|
|
|
101 |
|
102 |
enka_update = EnkaNetworkAPI()
|
103 |
|
104 |
+
app = Flask(__name__)
|
105 |
+
|
106 |
async def update_genshin():
|
107 |
async with enka_update:
|
108 |
await enka_update.update_assets(lang=["EN"], path="/tmp")
|
109 |
|
110 |
+
@app.before_first_request
|
111 |
+
def run_update_char():
|
112 |
+
"""
|
113 |
+
Run update_genshin before handling the first request.
|
114 |
+
"""
|
115 |
+
asyncio.run(update_genshin())
|
116 |
|
117 |
async def card(id, designtype):
|
118 |
async with enkacard.encbanner.ENC(uid=str(id)) as encard:
|
|
|
129 |
dt.card.save(byte_io, "PNG")
|
130 |
byte_io.seek(0)
|
131 |
image_url = upload_image(byte_io)
|
132 |
+
|
133 |
characters.append({
|
134 |
"name": dt.name,
|
135 |
"url": image_url
|
|
|
164 |
|
165 |
Parameters:
|
166 |
- data: A BytesIO object containing the image data.
|
|
|
167 |
Returns:
|
168 |
- A base64-encoded string of the image.
|
169 |
"""
|
170 |
# Convert the image data to a base64-encoded string
|
171 |
image_base64 = base64.b64encode(data.getvalue()).decode('utf-8')
|
172 |
+
|
173 |
# Return the base64-encoded string
|
174 |
return image_base64
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
|
176 |
if __name__ == "__main__":
|
177 |
app.run(debug=False, use_reloader=False)
|