DmitrMakeev
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1190,8 +1190,7 @@ def parse_csv_data(data):
|
|
1190 |
def insert_data(data):
|
1191 |
conn = sqlite3.connect(DATABASE2)
|
1192 |
cursor = conn.cursor()
|
1193 |
-
|
1194 |
-
data = reversed(data)
|
1195 |
for row in data:
|
1196 |
# Получение текущего времени в московском часовом поясе
|
1197 |
utc_now = datetime.utcnow()
|
@@ -1228,7 +1227,16 @@ def insert_data(data):
|
|
1228 |
n_con = row.get('n_con', '')
|
1229 |
canal = row.get('canal', '')
|
1230 |
|
1231 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1232 |
columns = ['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', 'curator', 'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'ad_url', 'key_pr', 'n_con', 'canal', 'data_t']
|
1233 |
values = [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, curator, pr1, pr2, pr3, pr4, pr5, ad_url, key_pr, n_con, canal, data_t]
|
1234 |
|
@@ -1236,7 +1244,7 @@ def insert_data(data):
|
|
1236 |
columns_str = ', '.join(columns)
|
1237 |
|
1238 |
query = f'''
|
1239 |
-
INSERT
|
1240 |
VALUES ({placeholders})
|
1241 |
'''
|
1242 |
|
@@ -1250,7 +1258,6 @@ def insert_data(data):
|
|
1250 |
|
1251 |
conn.commit()
|
1252 |
conn.close()
|
1253 |
-
|
1254 |
@app.route('/upload_csv', methods=['POST'])
|
1255 |
def upload_csv():
|
1256 |
if 'file' not in request.files:
|
|
|
1190 |
def insert_data(data):
|
1191 |
conn = sqlite3.connect(DATABASE2)
|
1192 |
cursor = conn.cursor()
|
1193 |
+
|
|
|
1194 |
for row in data:
|
1195 |
# Получение текущего времени в московском часовом поясе
|
1196 |
utc_now = datetime.utcnow()
|
|
|
1227 |
n_con = row.get('n_con', '')
|
1228 |
canal = row.get('canal', '')
|
1229 |
|
1230 |
+
# Проверка существования пользователя в базе данных по email
|
1231 |
+
cursor.execute("SELECT 1 FROM contacts WHERE email = ?", (email,))
|
1232 |
+
user_exists = cursor.fetchone()
|
1233 |
+
|
1234 |
+
# Если пользователь существует, пропускаем вставку
|
1235 |
+
if user_exists:
|
1236 |
+
print(f"User with email {email} already exists. Skipping insert.")
|
1237 |
+
continue
|
1238 |
+
|
1239 |
+
# Создание динамического SQL-запроса для вставки данных
|
1240 |
columns = ['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', 'curator', 'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'ad_url', 'key_pr', 'n_con', 'canal', 'data_t']
|
1241 |
values = [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, curator, pr1, pr2, pr3, pr4, pr5, ad_url, key_pr, n_con, canal, data_t]
|
1242 |
|
|
|
1244 |
columns_str = ', '.join(columns)
|
1245 |
|
1246 |
query = f'''
|
1247 |
+
INSERT INTO contacts ({columns_str})
|
1248 |
VALUES ({placeholders})
|
1249 |
'''
|
1250 |
|
|
|
1258 |
|
1259 |
conn.commit()
|
1260 |
conn.close()
|
|
|
1261 |
@app.route('/upload_csv', methods=['POST'])
|
1262 |
def upload_csv():
|
1263 |
if 'file' not in request.files:
|