DmitrMakeev
commited on
Commit
•
9565f93
1
Parent(s):
5f8f183
Update app.py
Browse files
app.py
CHANGED
@@ -265,10 +265,10 @@ def load_data_from_json(json_data):
|
|
265 |
query = '''
|
266 |
INSERT INTO contacts (
|
267 |
name, phone, email, vk_id, chat_id, ws_statys, ws_stop, web_statys, fin_progress, shop_statys_full, pr1, pr2, pr3, pr4, pr5, ad_url, curator, key_pr, n_con, canal, data_t,
|
268 |
-
b_fin, b_ban, b_ign, b_baners, b_butt, b_mess, shop_st
|
269 |
) VALUES (
|
270 |
:Имя, :Телефон, :Email, :vk_id, :chat_id, :ws_st, :ws_stop, :web_st, :fin_prog, :shop_st, :pr1, :pr2, :pr3, :pr4, :pr5, :ad_url, :curator, :key_pr, :n_con, :canal, :data_t,
|
271 |
-
:b_fin, :b_ban, :b_ign, :b_baners, :b_butt, :b_mess, :shop_st
|
272 |
)
|
273 |
'''
|
274 |
cursor.execute(query, user_data)
|
@@ -276,23 +276,9 @@ def load_data_from_json(json_data):
|
|
276 |
conn.commit()
|
277 |
conn.close()
|
278 |
|
279 |
-
@app.route('/start', methods=['GET'])
|
280 |
-
def start():
|
281 |
-
export_id = request.args.get('export_id')
|
282 |
-
api_key_sys_control = request.args.get('api_sys')
|
283 |
|
284 |
-
if export_id is None:
|
285 |
-
return json.dumps({"error": "export_id is required"}), 400
|
286 |
|
287 |
-
if api_key_sys_control != api_key_sys:
|
288 |
-
return json.dumps({"error": "Unauthorized access"}), 403
|
289 |
|
290 |
-
try:
|
291 |
-
json_data = send_second_request(export_id)
|
292 |
-
load_data_from_json(json_data)
|
293 |
-
return "Data loaded successfully", 200
|
294 |
-
except Exception as e:
|
295 |
-
return json.dumps({"error": str(e)}), 500
|
296 |
|
297 |
|
298 |
|
@@ -308,6 +294,39 @@ def start():
|
|
308 |
|
309 |
|
310 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
311 |
|
312 |
def randomize_message(template):
|
313 |
def replace_placeholder(match):
|
|
|
265 |
query = '''
|
266 |
INSERT INTO contacts (
|
267 |
name, phone, email, vk_id, chat_id, ws_statys, ws_stop, web_statys, fin_progress, shop_statys_full, pr1, pr2, pr3, pr4, pr5, ad_url, curator, key_pr, n_con, canal, data_t,
|
268 |
+
b_city, b_fin, b_ban, b_ign, b_baners, b_butt, b_mess, shop_st
|
269 |
) VALUES (
|
270 |
:Имя, :Телефон, :Email, :vk_id, :chat_id, :ws_st, :ws_stop, :web_st, :fin_prog, :shop_st, :pr1, :pr2, :pr3, :pr4, :pr5, :ad_url, :curator, :key_pr, :n_con, :canal, :data_t,
|
271 |
+
:b_city, :b_fin, :b_ban, :b_ign, :b_baners, :b_butt, :b_mess, :shop_st
|
272 |
)
|
273 |
'''
|
274 |
cursor.execute(query, user_data)
|
|
|
276 |
conn.commit()
|
277 |
conn.close()
|
278 |
|
|
|
|
|
|
|
|
|
279 |
|
|
|
|
|
280 |
|
|
|
|
|
281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
|
283 |
|
284 |
|
|
|
294 |
|
295 |
|
296 |
|
297 |
+
|
298 |
+
|
299 |
+
def send_second_request(export_id):
|
300 |
+
api_key = api_key_sys
|
301 |
+
api_url_template = 'https://school.riverpsy.com/pl/api/account/exports/{export_id}?key={api_key}'
|
302 |
+
api_url = api_url_template.format(export_id=export_id, api_key=api_key)
|
303 |
+
response = requests.get(api_url)
|
304 |
+
if response.status_code == 200:
|
305 |
+
return response.json()
|
306 |
+
else:
|
307 |
+
raise Exception(f"Failed to fetch data, status code: {response.status_code}")
|
308 |
+
|
309 |
+
@app.route('/start', methods=['GET'])
|
310 |
+
def start():
|
311 |
+
export_id = request.args.get('export_id')
|
312 |
+
api_key_sys_control = request.args.get('api_sys')
|
313 |
+
|
314 |
+
if export_id is None:
|
315 |
+
return jsonify({"error": "export_id is required"}), 400
|
316 |
+
|
317 |
+
if api_key_sys_control != api_key_sys:
|
318 |
+
return jsonify({"error": "Unauthorized access"}), 403
|
319 |
+
|
320 |
+
try:
|
321 |
+
json_data = send_second_request(export_id)
|
322 |
+
load_data_from_json(json_data)
|
323 |
+
return "Data loaded successfully", 200
|
324 |
+
except Exception as e:
|
325 |
+
return jsonify({"error": str(e)}), 500
|
326 |
+
|
327 |
+
|
328 |
+
|
329 |
+
|
330 |
|
331 |
def randomize_message(template):
|
332 |
def replace_placeholder(match):
|