DmitrMakeev
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -95,7 +95,7 @@ def init_db(db_name):
|
|
95 |
pr3 TEXT,
|
96 |
pr4 TEXT,
|
97 |
pr5 TEXT,
|
98 |
-
|
99 |
key_pr TEXT,
|
100 |
n_con TEXT,
|
101 |
canal TEXT,
|
@@ -306,7 +306,7 @@ def load_data_from_json(json_data):
|
|
306 |
user_data.setdefault('pr3', '')
|
307 |
user_data.setdefault('pr4', '')
|
308 |
user_data.setdefault('pr5', '')
|
309 |
-
user_data.setdefault('
|
310 |
user_data.setdefault('key_pr', '')
|
311 |
user_data.setdefault('n_con', '')
|
312 |
user_data.setdefault('canal', '')
|
@@ -317,9 +317,9 @@ def load_data_from_json(json_data):
|
|
317 |
|
318 |
query = '''
|
319 |
INSERT INTO contacts (
|
320 |
-
name, phone, email, vk_id, chat_id, ws_st, ws_stop, web_st, fin_prog, b_city, b_fin, b_ban, b_ign, b_baners, b_butt, b_mess, shop_st, pr1, pr2, pr3, pr4, pr5,
|
321 |
) VALUES (
|
322 |
-
:Имя, :Телефон, :Email, :vk_id, :chat_id, :ws_st, :ws_stop, :web_st, :fin_prog, :b_city, :b_fin, :b_ban, :b_ign, :b_baners, :b_butt, :b_mess, :shop_st, :pr1, :pr2, :pr3, :pr4, :pr5, :
|
323 |
)
|
324 |
'''
|
325 |
cursor.execute(query, user_data)
|
@@ -449,169 +449,6 @@ def start_mailings():
|
|
449 |
|
450 |
|
451 |
|
452 |
-
@app.route('/add_data_gc', methods=['GET'])
|
453 |
-
def add_data_gc():
|
454 |
-
try:
|
455 |
-
api_sys_control = request.args.get('api_sys')
|
456 |
-
|
457 |
-
if api_sys_control != api_key_sys:
|
458 |
-
return "err api key", 200
|
459 |
-
|
460 |
-
name = request.args.get('name')
|
461 |
-
phone = request.args.get('phone')
|
462 |
-
email = request.args.get('email')
|
463 |
-
vk_id = request.args.get('vk_id', '')
|
464 |
-
chat_id = request.args.get('chat_id')
|
465 |
-
ws_statys = request.args.get('ws_st')
|
466 |
-
ws_stop = request.args.get('ws_stop')
|
467 |
-
web_statys = request.args.get('web_st', 0, type=int)
|
468 |
-
fin_progress = request.args.get('fin_prog', 0, type=int)
|
469 |
-
shop_statys_full = request.args.get('shop_st')
|
470 |
-
pr1 = request.args.get('pr1')
|
471 |
-
pr2 = request.args.get('pr2')
|
472 |
-
pr3 = request.args.get('pr3')
|
473 |
-
pr4 = request.args.get('pr4')
|
474 |
-
pr5 = request.args.get('pr5')
|
475 |
-
ad_url = request.args.get('ad_url')
|
476 |
-
curator = request.args.get('curator')
|
477 |
-
key_pr = request.args.get('key_pr', '')
|
478 |
-
n_con = request.args.get('n_con', '')
|
479 |
-
canal = request.args.get('canal', '')
|
480 |
-
|
481 |
-
if not name or not phone or not email:
|
482 |
-
return "Parameters 'name', 'phone', and 'email' are required.", 400
|
483 |
-
|
484 |
-
# Clean up phone number by removing any leading plus sign
|
485 |
-
if phone.startswith('+'):
|
486 |
-
phone = phone[1:]
|
487 |
-
|
488 |
-
# Получение текущего времени в московском часовом поясе
|
489 |
-
utc_now = datetime.utcnow()
|
490 |
-
msk_tz = pytz.timezone('Europe/Moscow')
|
491 |
-
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
492 |
-
data_t = msk_now.strftime('%Y-%m-%d %H:%M:%S')
|
493 |
-
|
494 |
-
conn = sqlite3.connect('data_gc.db')
|
495 |
-
cursor = conn.cursor()
|
496 |
-
cursor.execute('SELECT * FROM contacts WHERE phone = ? OR email = ?', (phone, email))
|
497 |
-
existing_contact = cursor.fetchone()
|
498 |
-
|
499 |
-
if existing_contact:
|
500 |
-
cursor.execute('''
|
501 |
-
UPDATE contacts SET
|
502 |
-
name = ?, email = ?, vk_id = ?, chat_id = ?, ws_st = ?, ws_stop = ?,
|
503 |
-
web_st = ?, fin_prog = ?, shop_st = ?, pr1 = ?, pr2 = ?,
|
504 |
-
pr3 = ?, pr4 = ?, pr5 = ?, ad_url = ?, curator = ?, key_pr = ?, n_con = ?,
|
505 |
-
canal = ?, data_t = ?
|
506 |
-
WHERE phone = ? OR email = ?
|
507 |
-
''', (name, email, vk_id, chat_id, ws_statys, ws_stop, web_statys, fin_progress,
|
508 |
-
shop_statys_full, pr1, pr2, pr3, pr4, pr5, ad_url, curator, key_pr, n_con,
|
509 |
-
canal, data_t, phone, email))
|
510 |
-
else:
|
511 |
-
cursor.execute('''
|
512 |
-
INSERT INTO contacts (
|
513 |
-
name, phone, email, vk_id, chat_id, ws_st, ws_stop, web_st, fin_prog,
|
514 |
-
shop_st, pr1, pr2, pr3, pr4, pr5, ad_url, curator, key_pr, n_con, canal, data_t
|
515 |
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
516 |
-
''', (name, phone, email, vk_id, chat_id, ws_statys, ws_stop, web_statys, fin_progress,
|
517 |
-
shop_statys_full, pr1, pr2, pr3, pr4, pr5, ad_url, curator, key_pr, n_con, canal, data_t))
|
518 |
-
|
519 |
-
conn.commit()
|
520 |
-
conn.close()
|
521 |
-
|
522 |
-
return f"Contact updated/added: {name} - {phone} - {email}", 200
|
523 |
-
except Exception as e:
|
524 |
-
print(f"Error adding/updating contact: {e}")
|
525 |
-
return "Internal Server Error", 500
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
@app.route('/add_data_ras', methods=['GET'])
|
535 |
-
def add_data_ras():
|
536 |
-
try:
|
537 |
-
api_sys_control = request.args.get('api_sys')
|
538 |
-
|
539 |
-
if api_sys_control != api_key_sys:
|
540 |
-
return "EUR 22", 200
|
541 |
-
|
542 |
-
name = request.args.get('name')
|
543 |
-
phone = request.args.get('phone')
|
544 |
-
email = request.args.get('email')
|
545 |
-
vk_id = request.args.get('vk_id', '')
|
546 |
-
chat_id = request.args.get('chat_id', '')
|
547 |
-
ws_statys = request.args.get('ws_st', '')
|
548 |
-
ws_stop = request.args.get('ws_stop', '')
|
549 |
-
web_statys = request.args.get('web_st', 0, type=int)
|
550 |
-
fin_progress = request.args.get('fin_prog', 0, type=int)
|
551 |
-
shop_statys_full = request.args.get('shop_st', '')
|
552 |
-
pr1 = request.args.get('pr1', '')
|
553 |
-
pr2 = request.args.get('pr2', '')
|
554 |
-
pr3 = request.args.get('pr3', '')
|
555 |
-
pr4 = request.args.get('pr4', '')
|
556 |
-
pr5 = request.args.get('pr5', '')
|
557 |
-
ad_url = request.args.get('ad_url', '')
|
558 |
-
curator = request.args.get('curator', '')
|
559 |
-
key_pr = request.args.get('key_pr', '')
|
560 |
-
n_con = request.args.get('n_con', '')
|
561 |
-
canal = request.args.get('canal', '')
|
562 |
-
|
563 |
-
if not name or not phone or not email:
|
564 |
-
return "Parameters 'name', 'phone', and 'email' are required.", 400
|
565 |
-
|
566 |
-
# Clean up phone number by removing any leading plus sign
|
567 |
-
if phone.startswith('+'):
|
568 |
-
phone = phone[1:]
|
569 |
-
|
570 |
-
# Получение текущего времени в московском часовом поясе
|
571 |
-
utc_now = datetime.utcnow()
|
572 |
-
msk_tz = pytz.timezone('Europe/Moscow')
|
573 |
-
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
574 |
-
data_t = msk_now.strftime('%Y-%m-%d %H:%M:%S')
|
575 |
-
|
576 |
-
conn = sqlite3.connect('data1.db')
|
577 |
-
cursor = conn.cursor()
|
578 |
-
cursor.execute('SELECT * FROM contacts WHERE phone = ? OR email = ?', (phone, email))
|
579 |
-
existing_contact = cursor.fetchone()
|
580 |
-
|
581 |
-
if existing_contact:
|
582 |
-
cursor.execute('''
|
583 |
-
UPDATE contacts SET
|
584 |
-
name = ?, email = ?, vk_id = ?, chat_id = ?, ws_st = ?, ws_stop = ?,
|
585 |
-
web_st = ?, fin_prog = ?, shop_st = ?, pr1 = ?, pr2 = ?,
|
586 |
-
pr3 = ?, pr4 = ?, pr5 = ?, ad_url = ?, curator = ?, key_pr = ?, n_con = ?,
|
587 |
-
canal = ?, data_t = ?
|
588 |
-
WHERE phone = ? OR email = ?
|
589 |
-
''', (name, email, vk_id, chat_id, ws_statys, ws_stop, web_statys, fin_progress,
|
590 |
-
shop_statys_full, pr1, pr2, pr3, pr4, pr5, ad_url, curator, key_pr, n_con,
|
591 |
-
canal, data_t, phone, email))
|
592 |
-
else:
|
593 |
-
cursor.execute('''
|
594 |
-
INSERT INTO contacts (
|
595 |
-
name, phone, email, vk_id, chat_id, ws_st, ws_stop, web_st, fin_prog,
|
596 |
-
shop_st, pr1, pr2, pr3, pr4, pr5, ad_url, curator, key_pr, n_con, canal, data_t
|
597 |
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
598 |
-
''', (name, phone, email, vk_id, chat_id, ws_statys, ws_stop, web_statys, fin_progress,
|
599 |
-
shop_statys_full, pr1, pr2, pr3, pr4, pr5, ad_url, curator, key_pr, n_con, canal, data_t))
|
600 |
-
|
601 |
-
conn.commit()
|
602 |
-
conn.close()
|
603 |
-
|
604 |
-
return f"Contact updated/added: {name} - {phone} - {email}", 200
|
605 |
-
except Exception as e:
|
606 |
-
print(f"Error adding/updating contact: {e}")
|
607 |
-
return "Internal Server Error", 500
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
|
616 |
|
617 |
|
@@ -721,7 +558,7 @@ def data_gc_tab_out():
|
|
721 |
cursor.execute('''
|
722 |
SELECT id, name, phone, email, vk_id, chat_id, ws_st, ws_stop, web_st, fin_prog,
|
723 |
b_city, b_fin, b_ban, b_ign, b_baners, b_butt, b_mess, shop_st, curator,
|
724 |
-
pr1, pr2, pr3, pr4, pr5,
|
725 |
FROM contacts
|
726 |
''')
|
727 |
contacts = cursor.fetchall()
|
@@ -734,7 +571,7 @@ def data_gc_tab_out():
|
|
734 |
'b_ban': contact[12], 'b_ign': contact[13], 'b_baners': contact[14], 'b_butt': contact[15],
|
735 |
'b_mess': contact[16], 'shop_st': contact[17], 'curator': contact[18], 'pr1': contact[19],
|
736 |
'pr2': contact[20], 'pr3': contact[21], 'pr4': contact[22], 'pr5': contact[23],
|
737 |
-
'
|
738 |
'data_t': contact[28],'utm_source': contact[29], 'utm_medium': contact[30], 'utm_campaign': contact[31],
|
739 |
'utm_term': contact[32], 'utm_content': contact[33]
|
740 |
} for contact in contacts]
|
|
|
95 |
pr3 TEXT,
|
96 |
pr4 TEXT,
|
97 |
pr5 TEXT,
|
98 |
+
gc_url TEXT,
|
99 |
key_pr TEXT,
|
100 |
n_con TEXT,
|
101 |
canal TEXT,
|
|
|
306 |
user_data.setdefault('pr3', '')
|
307 |
user_data.setdefault('pr4', '')
|
308 |
user_data.setdefault('pr5', '')
|
309 |
+
user_data.setdefault('gc_url', '')
|
310 |
user_data.setdefault('key_pr', '')
|
311 |
user_data.setdefault('n_con', '')
|
312 |
user_data.setdefault('canal', '')
|
|
|
317 |
|
318 |
query = '''
|
319 |
INSERT INTO contacts (
|
320 |
+
name, phone, email, vk_id, chat_id, ws_st, ws_stop, web_st, fin_prog, b_city, b_fin, b_ban, b_ign, b_baners, b_butt, b_mess, shop_st, pr1, pr2, pr3, pr4, pr5, gc_url, curator, key_pr, n_con, canal, data_t
|
321 |
) VALUES (
|
322 |
+
:Имя, :Телефон, :Email, :vk_id, :chat_id, :ws_st, :ws_stop, :web_st, :fin_prog, :b_city, :b_fin, :b_ban, :b_ign, :b_baners, :b_butt, :b_mess, :shop_st, :pr1, :pr2, :pr3, :pr4, :pr5, :gc_url, :curator, :key_pr, :n_con, :canal, :data_t
|
323 |
)
|
324 |
'''
|
325 |
cursor.execute(query, user_data)
|
|
|
449 |
|
450 |
|
451 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
452 |
|
453 |
|
454 |
|
|
|
558 |
cursor.execute('''
|
559 |
SELECT id, name, phone, email, vk_id, chat_id, ws_st, ws_stop, web_st, fin_prog,
|
560 |
b_city, b_fin, b_ban, b_ign, b_baners, b_butt, b_mess, shop_st, curator,
|
561 |
+
pr1, pr2, pr3, pr4, pr5, gc_url, key_pr, n_con, canal, data_t, utm_source, utm_medium, utm_campaign, utm_term, utm_content
|
562 |
FROM contacts
|
563 |
''')
|
564 |
contacts = cursor.fetchall()
|
|
|
571 |
'b_ban': contact[12], 'b_ign': contact[13], 'b_baners': contact[14], 'b_butt': contact[15],
|
572 |
'b_mess': contact[16], 'shop_st': contact[17], 'curator': contact[18], 'pr1': contact[19],
|
573 |
'pr2': contact[20], 'pr3': contact[21], 'pr4': contact[22], 'pr5': contact[23],
|
574 |
+
'gc_url': contact[24], 'key_pr': contact[25], 'n_con': contact[26], 'canal': contact[27],
|
575 |
'data_t': contact[28],'utm_source': contact[29], 'utm_medium': contact[30], 'utm_campaign': contact[31],
|
576 |
'utm_term': contact[32], 'utm_content': contact[33]
|
577 |
} for contact in contacts]
|