DmitrMakeev commited on
Commit
19f25d6
1 Parent(s): e638fd6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -1228,17 +1228,20 @@ def insert_data(data):
1228
  n_con = row.get('n_con', '')
1229
  canal = row.get('canal', '')
1230
 
1231
- # Создание динамического SQL-запроса с использованием INSERT ... ON CONFLICT DO NOTHING
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
 
1235
  placeholders = ', '.join(['?' for _ in columns])
1236
  columns_str = ', '.join(columns)
1237
 
 
 
1238
  query = f'''
1239
  INSERT INTO contacts ({columns_str})
1240
  VALUES ({placeholders})
1241
- ON CONFLICT(email) DO NOTHING
 
1242
  '''
1243
 
1244
  try:
@@ -1253,6 +1256,7 @@ def insert_data(data):
1253
  conn.close()
1254
 
1255
 
 
1256
  @app.route('/upload_csv', methods=['POST'])
1257
  def upload_csv():
1258
  if 'file' not in request.files:
 
1228
  n_con = row.get('n_con', '')
1229
  canal = row.get('canal', '')
1230
 
1231
+ # Создание динамического SQL-запроса с использованием INSERT ON CONFLICT
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
 
1235
  placeholders = ', '.join(['?' for _ in columns])
1236
  columns_str = ', '.join(columns)
1237
 
1238
+ update_str = ', '.join([f"{col} = excluded.{col}" for col in columns if col != 'email'])
1239
+
1240
  query = f'''
1241
  INSERT INTO contacts ({columns_str})
1242
  VALUES ({placeholders})
1243
+ ON CONFLICT(email) DO UPDATE SET
1244
+ {update_str}
1245
  '''
1246
 
1247
  try:
 
1256
  conn.close()
1257
 
1258
 
1259
+
1260
  @app.route('/upload_csv', methods=['POST'])
1261
  def upload_csv():
1262
  if 'file' not in request.files: