Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -213,19 +213,23 @@ def export_user():
|
|
| 213 |
|
| 214 |
|
| 215 |
def send_second_request(export_id):
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
|
|
|
|
|
|
| 224 |
|
| 225 |
def load_data_from_json(json_data):
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
|
|
|
|
|
|
| 229 |
|
| 230 |
db = 'data_gc.db' # Указываем конкретную базу данных
|
| 231 |
conn = sqlite3.connect(db)
|
|
@@ -271,17 +275,18 @@ def start():
|
|
| 271 |
api_key_sys_control = request.args.get('api_sys')
|
| 272 |
|
| 273 |
if export_id is None:
|
| 274 |
-
return
|
| 275 |
|
| 276 |
if api_key_sys_control != api_key_sys:
|
| 277 |
-
return
|
| 278 |
|
| 279 |
try:
|
| 280 |
json_data = send_second_request(export_id)
|
| 281 |
load_data_from_json(json_data)
|
| 282 |
return "Data loaded successfully", 200
|
| 283 |
except Exception as e:
|
| 284 |
-
return
|
|
|
|
| 285 |
|
| 286 |
|
| 287 |
|
|
|
|
| 213 |
|
| 214 |
|
| 215 |
def send_second_request(export_id):
|
| 216 |
+
if export_id is None:
|
| 217 |
+
raise Exception("export_id is None")
|
| 218 |
+
# Формирование URL для второго запроса
|
| 219 |
+
export_url_template = f"https://school.riverpsy.com/pl/api/account/exports/{export_id}?key=jqgxSMUnHWoKUcxF3MHSb77VUMk7HpFbO9SHnfVYwHtwqe1S81lqeKxrLPoSPWCephtYQuJwMFsCXEFmyByXdruDpDFgf6L7ij66K9ji0Kf2qAIwbTqEyJGB5MOHwyHl"
|
| 220 |
+
try:
|
| 221 |
+
response = requests.get(export_url_template)
|
| 222 |
+
response.raise_for_status()
|
| 223 |
+
return response.json() # Возвращаем JSON-ответ сервера
|
| 224 |
+
except requests.RequestException as e:
|
| 225 |
+
raise Exception(f"Ошибка при выполнении запроса: {e}")
|
| 226 |
|
| 227 |
def load_data_from_json(json_data):
|
| 228 |
+
if 'info' not in json_data or 'items' not in json_data['info'] or 'fields' not in json_data['info']:
|
| 229 |
+
raise ValueError("Invalid JSON structure")
|
| 230 |
+
|
| 231 |
+
items = json_data['info']['items']
|
| 232 |
+
fields = json_data['info']['fields']
|
| 233 |
|
| 234 |
db = 'data_gc.db' # Указываем конкретную базу данных
|
| 235 |
conn = sqlite3.connect(db)
|
|
|
|
| 275 |
api_key_sys_control = request.args.get('api_sys')
|
| 276 |
|
| 277 |
if export_id is None:
|
| 278 |
+
return json.dumps({"error": "export_id is required"}), 400
|
| 279 |
|
| 280 |
if api_key_sys_control != api_key_sys:
|
| 281 |
+
return json.dumps({"error": "Unauthorized access"}), 403
|
| 282 |
|
| 283 |
try:
|
| 284 |
json_data = send_second_request(export_id)
|
| 285 |
load_data_from_json(json_data)
|
| 286 |
return "Data loaded successfully", 200
|
| 287 |
except Exception as e:
|
| 288 |
+
return json.dumps({"error": str(e)}), 500
|
| 289 |
+
|
| 290 |
|
| 291 |
|
| 292 |
|