DmitrMakeev
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -223,16 +223,21 @@ def load_data_from_json(json_data):
|
|
223 |
|
224 |
for item in items:
|
225 |
user_data = dict(zip(fields, item))
|
226 |
-
|
227 |
# Проверяем наличие значений для полей и устанавливаем значения по умолчанию, если они отсутствуют
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
|
237 |
# Убираем плюс в начале телефона, если он присутствует
|
238 |
if 'Телефон' in user_data and user_data['Телефон'].startswith('+'):
|
@@ -240,38 +245,33 @@ def load_data_from_json(json_data):
|
|
240 |
|
241 |
query = '''
|
242 |
INSERT INTO contacts (
|
243 |
-
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, canal, data_t
|
244 |
) VALUES (
|
245 |
:Имя, :Телефон, :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, :canal, :data_t
|
246 |
)
|
247 |
-
|
248 |
'''
|
249 |
cursor.execute(query, user_data)
|
250 |
|
251 |
conn.commit()
|
252 |
conn.close()
|
253 |
|
254 |
-
|
255 |
@app.route('/start', methods=['GET'])
|
256 |
def start():
|
257 |
export_id = request.args.get('export_id')
|
258 |
api_key_sys_control = request.args.get('api_sys')
|
259 |
|
260 |
if export_id is None:
|
261 |
-
return
|
262 |
|
263 |
if api_key_sys_control != api_key_sys:
|
264 |
-
return
|
265 |
|
266 |
try:
|
267 |
-
json_data = send_second_request(export_id)
|
268 |
load_data_from_json(json_data)
|
269 |
return "Data loaded successfully", 200
|
270 |
except Exception as e:
|
271 |
-
return
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
|
276 |
|
277 |
|
|
|
223 |
|
224 |
for item in items:
|
225 |
user_data = dict(zip(fields, item))
|
|
|
226 |
# Проверяем наличие значений для полей и устанавливаем значения по умолчанию, если они отсутствуют
|
227 |
+
user_data.setdefault('vk_id', '')
|
228 |
+
user_data.setdefault('chat_id', '')
|
229 |
+
user_data.setdefault('ws_st', '')
|
230 |
+
user_data.setdefault('ws_stop', '')
|
231 |
+
user_data.setdefault('web_st', '')
|
232 |
+
user_data.setdefault('fin_prog', '')
|
233 |
+
user_data.setdefault('shop_st', '')
|
234 |
+
user_data.setdefault('curator', '')
|
235 |
+
user_data.setdefault('pr1', '')
|
236 |
+
user_data.setdefault('pr2', '')
|
237 |
+
user_data.setdefault('pr3', '')
|
238 |
+
user_data.setdefault('pr4', '')
|
239 |
+
user_data.setdefault('pr5', '')
|
240 |
+
user_data.setdefault('ad_url', '')
|
241 |
|
242 |
# Убираем плюс в начале телефона, если он присутствует
|
243 |
if 'Телефон' in user_data and user_data['Телефон'].startswith('+'):
|
|
|
245 |
|
246 |
query = '''
|
247 |
INSERT INTO contacts (
|
248 |
+
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, canal, data_t
|
249 |
) VALUES (
|
250 |
:Имя, :Телефон, :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, :canal, :data_t
|
251 |
)
|
|
|
252 |
'''
|
253 |
cursor.execute(query, user_data)
|
254 |
|
255 |
conn.commit()
|
256 |
conn.close()
|
257 |
|
|
|
258 |
@app.route('/start', methods=['GET'])
|
259 |
def start():
|
260 |
export_id = request.args.get('export_id')
|
261 |
api_key_sys_control = request.args.get('api_sys')
|
262 |
|
263 |
if export_id is None:
|
264 |
+
return json.dumps({"error": "export_id is required"}), 400
|
265 |
|
266 |
if api_key_sys_control != api_key_sys:
|
267 |
+
return json.dumps({"error": "Unauthorized access"}), 403
|
268 |
|
269 |
try:
|
270 |
+
json_data = send_second_request(export_id)
|
271 |
load_data_from_json(json_data)
|
272 |
return "Data loaded successfully", 200
|
273 |
except Exception as e:
|
274 |
+
return json.dumps({"error": str(e)}), 500
|
|
|
|
|
|
|
275 |
|
276 |
|
277 |
|