DmitrMakeev
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1488,6 +1488,8 @@ def gc_forms():
|
|
1488 |
|
1489 |
|
1490 |
|
|
|
|
|
1491 |
# Глобальная переменная для управления верификацией
|
1492 |
curators = ["Anna", "Ekaterina", "Ivan", "Maria", "Sergey", "Olga", "Alex", "Natalia", "Dmitry", "Elena"]
|
1493 |
|
@@ -1570,8 +1572,8 @@ mapp_templates = {
|
|
1570 |
|
1571 |
DATABASE_NAME3 = 'data_gc.db'
|
1572 |
|
1573 |
-
def add_or_update_contact(contact_data
|
1574 |
-
conn = sqlite3.connect(
|
1575 |
cursor = conn.cursor()
|
1576 |
|
1577 |
email = contact_data.get('email')
|
@@ -1584,12 +1586,14 @@ def add_or_update_contact(contact_data, db_name):
|
|
1584 |
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
1585 |
contact_data['data_t'] = msk_now.strftime('%Y-%m-%d %H:%M:%S')
|
1586 |
|
|
|
1587 |
fields = [
|
1588 |
'name', 'phone', 'email', 'vk_id', 'chat_id', 'ws_st', 'ws_stop', 'web_st', 'fin_prog',
|
1589 |
'b_city', 'b_fin', 'b_ban', 'b_ign', 'b_baners', 'b_butt', 'b_mess', 'shop_st', 'curator',
|
1590 |
'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'gc_url', 'key_pr', 'n_con', 'canal', 'data_on', 'data_t', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gcpc'
|
1591 |
]
|
1592 |
|
|
|
1593 |
for field in fields:
|
1594 |
if field not in contact_data:
|
1595 |
contact_data[field] = ''
|
@@ -1608,16 +1612,15 @@ def add_or_update_contact(contact_data, db_name):
|
|
1608 |
cursor.execute(insert_query, tuple(contact_data[field] for field in fields))
|
1609 |
|
1610 |
conn.commit()
|
|
|
1611 |
conn.close()
|
1612 |
-
|
1613 |
@app.route('/ver_cur', methods=['GET'])
|
1614 |
def add_data_ver_cur():
|
1615 |
global current_curator_index
|
1616 |
|
1617 |
-
veref_on_off = request.args.get('ver', '0')
|
1618 |
-
curator_on_off = request.args.get('cur', '0')
|
1619 |
-
|
1620 |
-
|
1621 |
template_key = request.args.get('template_key', 'avp')
|
1622 |
mapping_template_cur = mapp_templates.get(template_key, mt_avp)
|
1623 |
|
@@ -1644,20 +1647,20 @@ def add_data_ver_cur():
|
|
1644 |
user_data['ws_st'] = user_data.get('ws_st', '')
|
1645 |
|
1646 |
try:
|
1647 |
-
add_or_update_contact(user_data
|
1648 |
return jsonify({'status': 'success', 'message': f'User added with curator {user_data.get("curator", "not assigned")}'})
|
1649 |
except Exception as e:
|
1650 |
logging.error(f"Error adding user: {e}")
|
1651 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
1652 |
|
|
|
1653 |
@app.route('/ver_bonus', methods=['GET'])
|
1654 |
def add_data_ver_bonus():
|
1655 |
global current_curator_index
|
1656 |
|
1657 |
-
veref_on_off = request.args.get('ver', '0')
|
1658 |
-
curator_on_off = request.args.get('cur', '0')
|
1659 |
-
|
1660 |
-
|
1661 |
template_key = request.args.get('template_key', 'avp')
|
1662 |
mapping_template_cur = mapp_templates.get(template_key, mt_avp)
|
1663 |
|
@@ -1683,10 +1686,11 @@ def add_data_ver_bonus():
|
|
1683 |
else:
|
1684 |
user_data['ws_st'] = user_data.get('ws_st', '')
|
1685 |
|
|
|
1686 |
email = user_data.get('email')
|
1687 |
new_pr1 = user_data.get('kol')
|
1688 |
if email and new_pr1:
|
1689 |
-
conn = sqlite3.connect(
|
1690 |
cursor = conn.cursor()
|
1691 |
cursor.execute("SELECT pr1 FROM contacts WHERE email = ?", (email,))
|
1692 |
result = cursor.fetchone()
|
@@ -1697,7 +1701,7 @@ def add_data_ver_bonus():
|
|
1697 |
conn.close()
|
1698 |
|
1699 |
try:
|
1700 |
-
add_or_update_contact(user_data
|
1701 |
return jsonify({'status': 'success', 'message': f'User added with curator {user_data.get("curator", "not assigned")}'})
|
1702 |
except Exception as e:
|
1703 |
logging.error(f"Error adding user: {e}")
|
|
|
1488 |
|
1489 |
|
1490 |
|
1491 |
+
|
1492 |
+
|
1493 |
# Глобальная переменная для управления верификацией
|
1494 |
curators = ["Anna", "Ekaterina", "Ivan", "Maria", "Sergey", "Olga", "Alex", "Natalia", "Dmitry", "Elena"]
|
1495 |
|
|
|
1572 |
|
1573 |
DATABASE_NAME3 = 'data_gc.db'
|
1574 |
|
1575 |
+
def add_or_update_contact(contact_data):
|
1576 |
+
conn = sqlite3.connect(DATABASE_NAME3)
|
1577 |
cursor = conn.cursor()
|
1578 |
|
1579 |
email = contact_data.get('email')
|
|
|
1586 |
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
1587 |
contact_data['data_t'] = msk_now.strftime('%Y-%m-%d %H:%M:%S')
|
1588 |
|
1589 |
+
# Список всех возможных полей
|
1590 |
fields = [
|
1591 |
'name', 'phone', 'email', 'vk_id', 'chat_id', 'ws_st', 'ws_stop', 'web_st', 'fin_prog',
|
1592 |
'b_city', 'b_fin', 'b_ban', 'b_ign', 'b_baners', 'b_butt', 'b_mess', 'shop_st', 'curator',
|
1593 |
'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'gc_url', 'key_pr', 'n_con', 'canal', 'data_on', 'data_t', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gcpc'
|
1594 |
]
|
1595 |
|
1596 |
+
# Устанавливаем значения по умолчанию для отсутствующих полей
|
1597 |
for field in fields:
|
1598 |
if field not in contact_data:
|
1599 |
contact_data[field] = ''
|
|
|
1612 |
cursor.execute(insert_query, tuple(contact_data[field] for field in fields))
|
1613 |
|
1614 |
conn.commit()
|
1615 |
+
replace_null_with_empty_string(conn)
|
1616 |
conn.close()
|
|
|
1617 |
@app.route('/ver_cur', methods=['GET'])
|
1618 |
def add_data_ver_cur():
|
1619 |
global current_curator_index
|
1620 |
|
1621 |
+
veref_on_off = request.args.get('ver', '0') # Включает "1" и выключает "0" верификацию номера вместо verifikation_start
|
1622 |
+
curator_on_off = request.args.get('cur', '0') # Включает "1" и выключает "0" назначение куратора
|
1623 |
+
|
|
|
1624 |
template_key = request.args.get('template_key', 'avp')
|
1625 |
mapping_template_cur = mapp_templates.get(template_key, mt_avp)
|
1626 |
|
|
|
1647 |
user_data['ws_st'] = user_data.get('ws_st', '')
|
1648 |
|
1649 |
try:
|
1650 |
+
add_or_update_contact(user_data)
|
1651 |
return jsonify({'status': 'success', 'message': f'User added with curator {user_data.get("curator", "not assigned")}'})
|
1652 |
except Exception as e:
|
1653 |
logging.error(f"Error adding user: {e}")
|
1654 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
1655 |
|
1656 |
+
|
1657 |
@app.route('/ver_bonus', methods=['GET'])
|
1658 |
def add_data_ver_bonus():
|
1659 |
global current_curator_index
|
1660 |
|
1661 |
+
veref_on_off = request.args.get('ver', '0') # Включает "1" и выключает "0" верификацию номера вместо verifikation_start
|
1662 |
+
curator_on_off = request.args.get('cur', '0') # Включает "1" и выключает "0" назначение куратора
|
1663 |
+
|
|
|
1664 |
template_key = request.args.get('template_key', 'avp')
|
1665 |
mapping_template_cur = mapp_templates.get(template_key, mt_avp)
|
1666 |
|
|
|
1686 |
else:
|
1687 |
user_data['ws_st'] = user_data.get('ws_st', '')
|
1688 |
|
1689 |
+
# Обработка kol для pr1
|
1690 |
email = user_data.get('email')
|
1691 |
new_pr1 = user_data.get('kol')
|
1692 |
if email and new_pr1:
|
1693 |
+
conn = sqlite3.connect(DATABASE_NAME3)
|
1694 |
cursor = conn.cursor()
|
1695 |
cursor.execute("SELECT pr1 FROM contacts WHERE email = ?", (email,))
|
1696 |
result = cursor.fetchone()
|
|
|
1701 |
conn.close()
|
1702 |
|
1703 |
try:
|
1704 |
+
add_or_update_contact(user_data)
|
1705 |
return jsonify({'status': 'success', 'message': f'User added with curator {user_data.get("curator", "not assigned")}'})
|
1706 |
except Exception as e:
|
1707 |
logging.error(f"Error adding user: {e}")
|