DmitrMakeev
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1572,8 +1572,8 @@ mapp_templates = {
|
|
1572 |
|
1573 |
DATABASE_NAME3 = 'data_gc.db'
|
1574 |
|
1575 |
-
def add_or_update_contact(contact_data):
|
1576 |
-
conn = sqlite3.connect(
|
1577 |
cursor = conn.cursor()
|
1578 |
|
1579 |
email = contact_data.get('email')
|
@@ -1586,14 +1586,12 @@ def add_or_update_contact(contact_data):
|
|
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,15 +1610,16 @@ def add_or_update_contact(contact_data):
|
|
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')
|
1622 |
-
curator_on_off = request.args.get('cur', '0')
|
1623 |
-
|
|
|
1624 |
template_key = request.args.get('template_key', 'avp')
|
1625 |
mapping_template_cur = mapp_templates.get(template_key, mt_avp)
|
1626 |
|
@@ -1647,20 +1646,20 @@ def add_data_ver_cur():
|
|
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')
|
1662 |
-
curator_on_off = request.args.get('cur', '0')
|
1663 |
-
|
|
|
1664 |
template_key = request.args.get('template_key', 'avp')
|
1665 |
mapping_template_cur = mapp_templates.get(template_key, mt_avp)
|
1666 |
|
@@ -1686,11 +1685,10 @@ def add_data_ver_bonus():
|
|
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(
|
1694 |
cursor = conn.cursor()
|
1695 |
cursor.execute("SELECT pr1 FROM contacts WHERE email = ?", (email,))
|
1696 |
result = cursor.fetchone()
|
@@ -1701,7 +1699,7 @@ def add_data_ver_bonus():
|
|
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}")
|
@@ -1728,7 +1726,6 @@ def add_data_ver_bonus():
|
|
1728 |
|
1729 |
|
1730 |
|
1731 |
-
|
1732 |
|
1733 |
|
1734 |
def clean_phone_number_ss(phone_number):
|
|
|
1572 |
|
1573 |
DATABASE_NAME3 = 'data_gc.db'
|
1574 |
|
1575 |
+
def add_or_update_contact(contact_data, db_name):
|
1576 |
+
conn = sqlite3.connect(db_name)
|
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 |
fields = [
|
1590 |
'name', 'phone', 'email', 'vk_id', 'chat_id', 'ws_st', 'ws_stop', 'web_st', 'fin_prog',
|
1591 |
'b_city', 'b_fin', 'b_ban', 'b_ign', 'b_baners', 'b_butt', 'b_mess', 'shop_st', 'curator',
|
1592 |
'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'
|
1593 |
]
|
1594 |
|
|
|
1595 |
for field in fields:
|
1596 |
if field not in contact_data:
|
1597 |
contact_data[field] = ''
|
|
|
1610 |
cursor.execute(insert_query, tuple(contact_data[field] for field in fields))
|
1611 |
|
1612 |
conn.commit()
|
|
|
1613 |
conn.close()
|
1614 |
+
|
1615 |
@app.route('/ver_cur', methods=['GET'])
|
1616 |
def add_data_ver_cur():
|
1617 |
global current_curator_index
|
1618 |
|
1619 |
+
veref_on_off = request.args.get('ver', '0')
|
1620 |
+
curator_on_off = request.args.get('cur', '0')
|
1621 |
+
db_name = request.args.get('db', 'data_gc.db') # Получаем имя базы данных из запроса
|
1622 |
+
|
1623 |
template_key = request.args.get('template_key', 'avp')
|
1624 |
mapping_template_cur = mapp_templates.get(template_key, mt_avp)
|
1625 |
|
|
|
1646 |
user_data['ws_st'] = user_data.get('ws_st', '')
|
1647 |
|
1648 |
try:
|
1649 |
+
add_or_update_contact(user_data, db_name)
|
1650 |
return jsonify({'status': 'success', 'message': f'User added with curator {user_data.get("curator", "not assigned")}'})
|
1651 |
except Exception as e:
|
1652 |
logging.error(f"Error adding user: {e}")
|
1653 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
1654 |
|
|
|
1655 |
@app.route('/ver_bonus', methods=['GET'])
|
1656 |
def add_data_ver_bonus():
|
1657 |
global current_curator_index
|
1658 |
|
1659 |
+
veref_on_off = request.args.get('ver', '0')
|
1660 |
+
curator_on_off = request.args.get('cur', '0')
|
1661 |
+
db_name = request.args.get('db', 'data_gc.db') # Получаем имя базы данных из запроса
|
1662 |
+
|
1663 |
template_key = request.args.get('template_key', 'avp')
|
1664 |
mapping_template_cur = mapp_templates.get(template_key, mt_avp)
|
1665 |
|
|
|
1685 |
else:
|
1686 |
user_data['ws_st'] = user_data.get('ws_st', '')
|
1687 |
|
|
|
1688 |
email = user_data.get('email')
|
1689 |
new_pr1 = user_data.get('kol')
|
1690 |
if email and new_pr1:
|
1691 |
+
conn = sqlite3.connect(db_name)
|
1692 |
cursor = conn.cursor()
|
1693 |
cursor.execute("SELECT pr1 FROM contacts WHERE email = ?", (email,))
|
1694 |
result = cursor.fetchone()
|
|
|
1699 |
conn.close()
|
1700 |
|
1701 |
try:
|
1702 |
+
add_or_update_contact(user_data, db_name)
|
1703 |
return jsonify({'status': 'success', 'message': f'User added with curator {user_data.get("curator", "not assigned")}'})
|
1704 |
except Exception as e:
|
1705 |
logging.error(f"Error adding user: {e}")
|
|
|
1726 |
|
1727 |
|
1728 |
|
|
|
1729 |
|
1730 |
|
1731 |
def clean_phone_number_ss(phone_number):
|