Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -284,6 +284,49 @@ def biz_v():
|
|
| 284 |
|
| 285 |
|
| 286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
|
| 288 |
|
| 289 |
|
|
|
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
+
@app.route('/upload_csv', methods=['POST'])
|
| 288 |
+
def upload_csv():
|
| 289 |
+
if 'file' not in request.files:
|
| 290 |
+
return jsonify({"error": "No file part"}), 400
|
| 291 |
+
file = request.files['file']
|
| 292 |
+
if file.filename == '':
|
| 293 |
+
return jsonify({"error": "No selected file"}), 400
|
| 294 |
+
if file and file.filename.endswith('.csv'):
|
| 295 |
+
stream = io.StringIO(file.stream.read().decode("UTF8"), newline=None)
|
| 296 |
+
csv_input = csv.DictReader(stream)
|
| 297 |
+
data = [row for row in csv_input]
|
| 298 |
+
parsed_data = parse_csv_data(data)
|
| 299 |
+
verify_phone = request.form.get('verify_phone', '0')
|
| 300 |
+
add_curator = request.form.get('add_curator', '0')
|
| 301 |
+
print(f"Verify Phone: {verify_phone}")
|
| 302 |
+
print(f"Add Curator: {add_curator}")
|
| 303 |
+
insert_data(parsed_data, verify_phone, add_curator)
|
| 304 |
+
return jsonify({"message": "Data uploaded and inserted successfully"})
|
| 305 |
+
return jsonify({"error": "Invalid file format"}), 400
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
# Маршрут для загрузки JSON-файла
|
| 310 |
+
@app.route('/upload_json', methods=['POST'])
|
| 311 |
+
def upload_json():
|
| 312 |
+
if 'file' not in request.files:
|
| 313 |
+
return jsonify({"error": "No file part"}), 400
|
| 314 |
+
file = request.files['file']
|
| 315 |
+
if file.filename == '':
|
| 316 |
+
return jsonify({"error": "No selected file"}), 400
|
| 317 |
+
if file and file.filename.endswith('.json'):
|
| 318 |
+
data = json.load(file)
|
| 319 |
+
insert_data_j(data)
|
| 320 |
+
return jsonify({"message": "Data uploaded and inserted successfully"})
|
| 321 |
+
return jsonify({"error": "Invalid file format"}), 400
|
| 322 |
+
|
| 323 |
+
# Маршрут для отображения формы загрузки JSON
|
| 324 |
+
@app.route('/upl_json', methods=['GET'])
|
| 325 |
+
def display_form():
|
| 326 |
+
return render_template('upload_json.html')
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
|
| 330 |
|
| 331 |
|
| 332 |
|