Update app.py
Browse files
app.py
CHANGED
@@ -1703,7 +1703,6 @@ def verify_phone_number2(phone_number):
|
|
1703 |
else:
|
1704 |
return "false"
|
1705 |
|
1706 |
-
# Функция для обработки CSV данных
|
1707 |
def parse_csv_data(data):
|
1708 |
parsed_data = []
|
1709 |
for item in data:
|
@@ -1713,7 +1712,6 @@ def parse_csv_data(data):
|
|
1713 |
parsed_data.append(dict(zip(headers, row)))
|
1714 |
return parsed_data
|
1715 |
|
1716 |
-
# Функция для вставки данных в базу данных
|
1717 |
def insert_data(data, template_key):
|
1718 |
global current_curator_index
|
1719 |
conn = sqlite3.connect(DATABASE2)
|
@@ -1722,7 +1720,6 @@ def insert_data(data, template_key):
|
|
1722 |
mapping_template_cur = mapp_templates.get(template_key, mt_avp)
|
1723 |
|
1724 |
for row in data:
|
1725 |
-
# Получение текущего времени в московском часовом поясе
|
1726 |
utc_now = datetime.utcnow()
|
1727 |
msk_tz = pytz.timezone('Europe/Moscow')
|
1728 |
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
@@ -1738,21 +1735,17 @@ def insert_data(data, template_key):
|
|
1738 |
print(f"Missing required fields in row: {row}. Skipping insert.")
|
1739 |
continue
|
1740 |
|
1741 |
-
# Проверка существования пользователя в базе данных по email или телефону
|
1742 |
cursor.execute("SELECT 1 FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
1743 |
user_exists = cursor.fetchone()
|
1744 |
|
1745 |
-
# Если пользователь существует, пропускаем вставку
|
1746 |
if user_exists:
|
1747 |
print(f"User with email {email} or phone {phone} already exists. Skipping insert.")
|
1748 |
continue
|
1749 |
|
1750 |
-
# Назначение куратора
|
1751 |
if curator_on_off == "1":
|
1752 |
user_data['curator'] = curators[current_curator_index]
|
1753 |
current_curator_index = (current_curator_index + 1) % len(curators)
|
1754 |
|
1755 |
-
# Верификация номера телефона
|
1756 |
if verifikation_start == "1":
|
1757 |
user_data['ws_st'] = verify_phone_number2(phone)
|
1758 |
|
@@ -1774,16 +1767,22 @@ def insert_data(data, template_key):
|
|
1774 |
|
1775 |
try:
|
1776 |
cursor.execute(query, [user_data.get(field, '') for field in fields])
|
|
|
1777 |
except Exception as e:
|
1778 |
print(f"Error inserting row: {row}")
|
1779 |
print(f"Error message: {str(e)}")
|
1780 |
conn.rollback()
|
1781 |
raise
|
1782 |
|
1783 |
-
|
1784 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1785 |
|
1786 |
-
# Проверка ключа API
|
1787 |
def verify_api_key():
|
1788 |
api_key = request.args.get('api_sys')
|
1789 |
if api_key != "fasSd345D":
|
@@ -1836,7 +1835,6 @@ def upload_csv():
|
|
1836 |
|
1837 |
|
1838 |
|
1839 |
-
|
1840 |
|
1841 |
|
1842 |
@app.route('/gc_in', methods=['GET'])
|
|
|
1703 |
else:
|
1704 |
return "false"
|
1705 |
|
|
|
1706 |
def parse_csv_data(data):
|
1707 |
parsed_data = []
|
1708 |
for item in data:
|
|
|
1712 |
parsed_data.append(dict(zip(headers, row)))
|
1713 |
return parsed_data
|
1714 |
|
|
|
1715 |
def insert_data(data, template_key):
|
1716 |
global current_curator_index
|
1717 |
conn = sqlite3.connect(DATABASE2)
|
|
|
1720 |
mapping_template_cur = mapp_templates.get(template_key, mt_avp)
|
1721 |
|
1722 |
for row in data:
|
|
|
1723 |
utc_now = datetime.utcnow()
|
1724 |
msk_tz = pytz.timezone('Europe/Moscow')
|
1725 |
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
|
|
1735 |
print(f"Missing required fields in row: {row}. Skipping insert.")
|
1736 |
continue
|
1737 |
|
|
|
1738 |
cursor.execute("SELECT 1 FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
1739 |
user_exists = cursor.fetchone()
|
1740 |
|
|
|
1741 |
if user_exists:
|
1742 |
print(f"User with email {email} or phone {phone} already exists. Skipping insert.")
|
1743 |
continue
|
1744 |
|
|
|
1745 |
if curator_on_off == "1":
|
1746 |
user_data['curator'] = curators[current_curator_index]
|
1747 |
current_curator_index = (current_curator_index + 1) % len(curators)
|
1748 |
|
|
|
1749 |
if verifikation_start == "1":
|
1750 |
user_data['ws_st'] = verify_phone_number2(phone)
|
1751 |
|
|
|
1767 |
|
1768 |
try:
|
1769 |
cursor.execute(query, [user_data.get(field, '') for field in fields])
|
1770 |
+
print(f"Row inserted successfully: {user_data}")
|
1771 |
except Exception as e:
|
1772 |
print(f"Error inserting row: {row}")
|
1773 |
print(f"Error message: {str(e)}")
|
1774 |
conn.rollback()
|
1775 |
raise
|
1776 |
|
1777 |
+
try:
|
1778 |
+
conn.commit()
|
1779 |
+
print("Transaction committed successfully.")
|
1780 |
+
except Exception as e:
|
1781 |
+
print(f"Error committing transaction: {str(e)}")
|
1782 |
+
conn.rollback()
|
1783 |
+
finally:
|
1784 |
+
conn.close()
|
1785 |
|
|
|
1786 |
def verify_api_key():
|
1787 |
api_key = request.args.get('api_sys')
|
1788 |
if api_key != "fasSd345D":
|
|
|
1835 |
|
1836 |
|
1837 |
|
|
|
1838 |
|
1839 |
|
1840 |
@app.route('/gc_in', methods=['GET'])
|