DmitrMakeev
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1695,7 +1695,6 @@ def verify_phone_number2(phone_number):
|
|
1695 |
else:
|
1696 |
return "false"
|
1697 |
|
1698 |
-
# Функция для парсинга данных из CSV
|
1699 |
def parse_csv_data(data):
|
1700 |
parsed_data = []
|
1701 |
for item in data:
|
@@ -1705,7 +1704,6 @@ def parse_csv_data(data):
|
|
1705 |
parsed_data.append(dict(zip(headers, row)))
|
1706 |
return parsed_data
|
1707 |
|
1708 |
-
# Функция для вставки данных в базу данных
|
1709 |
def insert_data2(data, template_key):
|
1710 |
global current_curator_index
|
1711 |
conn = sqlite3.connect(DATABASE2)
|
@@ -1726,14 +1724,14 @@ def insert_data2(data, template_key):
|
|
1726 |
email = user_data.get('email', '')
|
1727 |
|
1728 |
if not name or not phone or not email:
|
1729 |
-
|
1730 |
continue
|
1731 |
|
1732 |
cursor.execute("SELECT 1 FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
1733 |
user_exists = cursor.fetchone()
|
1734 |
|
1735 |
if user_exists:
|
1736 |
-
|
1737 |
continue
|
1738 |
|
1739 |
if curator_on_off == "1":
|
@@ -1761,29 +1759,27 @@ def insert_data2(data, template_key):
|
|
1761 |
|
1762 |
try:
|
1763 |
cursor.execute(query, [user_data.get(field, '') for field in fields])
|
1764 |
-
|
1765 |
except Exception as e:
|
1766 |
-
|
1767 |
-
|
1768 |
conn.rollback()
|
1769 |
raise
|
1770 |
|
1771 |
try:
|
1772 |
conn.commit()
|
1773 |
-
|
1774 |
except Exception as e:
|
1775 |
-
|
1776 |
conn.rollback()
|
1777 |
finally:
|
1778 |
conn.close()
|
1779 |
|
1780 |
-
# Функция для проверки API ключа
|
1781 |
def verify_api_key():
|
1782 |
api_key = request.args.get('api_sys')
|
1783 |
if api_key != "fasSd345D":
|
1784 |
return jsonify({"error": "Invalid API key"}), 403
|
1785 |
|
1786 |
-
# Маршрут для загрузки CSV файла и вставки данных в базу данных
|
1787 |
@app.route('/upload_csv', methods=['POST'])
|
1788 |
def upload_csv():
|
1789 |
if 'file' not in request.files:
|
|
|
1695 |
else:
|
1696 |
return "false"
|
1697 |
|
|
|
1698 |
def parse_csv_data(data):
|
1699 |
parsed_data = []
|
1700 |
for item in data:
|
|
|
1704 |
parsed_data.append(dict(zip(headers, row)))
|
1705 |
return parsed_data
|
1706 |
|
|
|
1707 |
def insert_data2(data, template_key):
|
1708 |
global current_curator_index
|
1709 |
conn = sqlite3.connect(DATABASE2)
|
|
|
1724 |
email = user_data.get('email', '')
|
1725 |
|
1726 |
if not name or not phone or not email:
|
1727 |
+
logging.error(f"Missing required fields in row: {row}. Skipping insert.")
|
1728 |
continue
|
1729 |
|
1730 |
cursor.execute("SELECT 1 FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
1731 |
user_exists = cursor.fetchone()
|
1732 |
|
1733 |
if user_exists:
|
1734 |
+
logging.debug(f"User with email {email} or phone {phone} already exists. Skipping insert.")
|
1735 |
continue
|
1736 |
|
1737 |
if curator_on_off == "1":
|
|
|
1759 |
|
1760 |
try:
|
1761 |
cursor.execute(query, [user_data.get(field, '') for field in fields])
|
1762 |
+
logging.debug(f"Row inserted successfully: {user_data}")
|
1763 |
except Exception as e:
|
1764 |
+
logging.error(f"Error inserting row: {row}")
|
1765 |
+
logging.error(f"Error message: {str(e)}")
|
1766 |
conn.rollback()
|
1767 |
raise
|
1768 |
|
1769 |
try:
|
1770 |
conn.commit()
|
1771 |
+
logging.debug("Transaction committed successfully.")
|
1772 |
except Exception as e:
|
1773 |
+
logging.error(f"Error committing transaction: {str(e)}")
|
1774 |
conn.rollback()
|
1775 |
finally:
|
1776 |
conn.close()
|
1777 |
|
|
|
1778 |
def verify_api_key():
|
1779 |
api_key = request.args.get('api_sys')
|
1780 |
if api_key != "fasSd345D":
|
1781 |
return jsonify({"error": "Invalid API key"}), 403
|
1782 |
|
|
|
1783 |
@app.route('/upload_csv', methods=['POST'])
|
1784 |
def upload_csv():
|
1785 |
if 'file' not in request.files:
|