DmitrMakeev
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -214,22 +214,20 @@ def export_user():
|
|
214 |
|
215 |
|
216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
def load_data_from_json():
|
232 |
-
data = json.loads(json_data)
|
233 |
items = data['info']['items']
|
234 |
fields = data['info']['fields']
|
235 |
|
@@ -271,9 +269,30 @@ def load_data_from_json():
|
|
271 |
conn.commit()
|
272 |
conn.close()
|
273 |
|
274 |
-
@app.
|
275 |
-
def
|
276 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
|
278 |
|
279 |
|
|
|
214 |
|
215 |
|
216 |
|
217 |
+
def send_second_request(export_id):
|
218 |
+
if export_id is None:
|
219 |
+
raise Exception("export_id is None")
|
220 |
+
# Формирование URL для второго запроса
|
221 |
+
export_url_template = f"https://school.riverpsy.com/pl/api/account/exports/{export_id}?key=jqgxSMUnHWoKUcxF3MHSb77VUMk7HpFbO9SHnfVYwHtwqe1S81lqeKxrLPoSPWCephtYQuJwMFsCXEFmyByXdruDpDFgf6L7ij66K9ji0Kf2qAIwbTqEyJGB5MOHwyHl"
|
222 |
+
try:
|
223 |
+
response = requests.get(export_url_template)
|
224 |
+
response.raise_for_status()
|
225 |
+
return response.json() # Возвращаем JSON-ответ сервера
|
226 |
+
except requests.RequestException as e:
|
227 |
+
raise Exception(f"Ошибка при выполнении запроса: {e}")
|
228 |
|
229 |
+
def load_data_from_json(json_data):
|
230 |
+
data = json_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
items = data['info']['items']
|
232 |
fields = data['info']['fields']
|
233 |
|
|
|
269 |
conn.commit()
|
270 |
conn.close()
|
271 |
|
272 |
+
@app.route('/start_up', methods=['GET'])
|
273 |
+
def start_up():
|
274 |
+
export_id = request.args.get('export_id')
|
275 |
+
if export_id is None:
|
276 |
+
return json.dumps({"error": "export_id is required"}), 400
|
277 |
+
|
278 |
+
try:
|
279 |
+
json_data = send_second_request(export_id)
|
280 |
+
load_data_from_json(json_data)
|
281 |
+
return "Data loaded successfully", 200
|
282 |
+
except Exception as e:
|
283 |
+
return json.dumps({"error": str(e)}), 500
|
284 |
+
|
285 |
+
|
286 |
+
|
287 |
+
|
288 |
+
|
289 |
+
|
290 |
+
|
291 |
+
|
292 |
+
|
293 |
+
|
294 |
+
|
295 |
+
|
296 |
|
297 |
|
298 |
|