ambon commited on
Commit
d885278
·
verified ·
1 Parent(s): 9ea7cfa

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +30 -25
main.py CHANGED
@@ -88,6 +88,7 @@
88
 
89
  # if __name__ == "__main__":
90
  # app.run(debug=False, use_reloader=False)
 
91
  import enkacard
92
  import enkacard.encbanner
93
  import enkanetwork
@@ -101,24 +102,11 @@ import base64
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_serving
111
- def updet():
112
- """
113
- Run update_genshin before handling the first request.
114
- """
115
- data_dirs = ["/tmp/data", "/tmp/langs"]
116
-
117
- for directory in data_dirs:
118
- if not os.path.exists(directory):
119
- os.makedirs(directory)
120
-
121
- asyncio.run(update_genshin())
122
 
123
  async def card(id, designtype):
124
  async with enkacard.encbanner.ENC(uid=str(id)) as encard:
@@ -135,7 +123,7 @@ def characters(id):
135
  dt.card.save(byte_io, "PNG")
136
  byte_io.seek(0)
137
  image_url = upload_image(byte_io)
138
-
139
  characters.append({
140
  "name": dt.name,
141
  "url": image_url
@@ -153,16 +141,16 @@ def characters(id):
153
  def hello_world():
154
  return 'AMERICA YA HALLO!!'
155
 
156
- # @app.route("/update_char")
157
- # def upload():
158
- # data_dirs = ["/tmp/data", "/tmp/langs"]
159
 
160
- # for directory in data_dirs:
161
- # if not os.path.exists(directory):
162
- # os.makedirs(directory)
163
 
164
- # asyncio.run(update_genshin())
165
- # return 'Update completed!'
166
 
167
  def upload_image(data):
168
  """
@@ -170,14 +158,31 @@ def upload_image(data):
170
 
171
  Parameters:
172
  - data: A BytesIO object containing the image data.
 
173
  Returns:
174
  - A base64-encoded string of the image.
175
  """
176
  # Convert the image data to a base64-encoded string
177
  image_base64 = base64.b64encode(data.getvalue()).decode('utf-8')
178
-
179
  # Return the base64-encoded string
180
  return image_base64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
 
182
  if __name__ == "__main__":
183
- app.run(debug=False, use_reloader=False)
 
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
 
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 = Flask(__name__)
 
 
 
 
 
 
 
 
 
 
 
110
 
111
  async def card(id, designtype):
112
  async with enkacard.encbanner.ENC(uid=str(id)) as encard:
 
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
 
141
  def hello_world():
142
  return 'AMERICA YA HALLO!!'
143
 
144
+ @app.route("/update_char")
145
+ def upload():
146
+ data_dirs = ["/tmp/data", "/tmp/langs"]
147
 
148
+ for directory in data_dirs:
149
+ if not os.path.exists(directory):
150
+ os.makedirs(directory)
151
 
152
+ asyncio.run(update_genshin())
153
+ return 'Update completed!'
154
 
155
  def upload_image(data):
156
  """
 
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)