DmitrMakeev commited on
Commit
cfc6186
·
verified ·
1 Parent(s): 7b25582

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -2033,7 +2033,6 @@ def from_allow():
2033
  if api_sys_control != api_key_sys:
2034
  return jsonify({"error": "Unauthorized access"}), 403
2035
 
2036
- name = request.args.get('name', '')
2037
  email = request.args.get('email', '')
2038
  phone = request.args.get('phone', '').lstrip('+')
2039
  module = request.args.get('module', '')
@@ -2057,8 +2056,8 @@ def from_allow():
2057
  else:
2058
  pr5_data = {}
2059
 
2060
- if del_flag == '1':
2061
- pr5_data = {}
2062
  elif module and status:
2063
  pr5_data[module] = status
2064
 
@@ -2069,16 +2068,17 @@ def from_allow():
2069
  msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
2070
  data_on = msk_now.strftime('%Y-%m-%d %H:%M:%S')
2071
 
2072
- columns_to_update = ['name', 'phone', 'email', 'pr5', 'data_on']
2073
- values_to_update = [name, phone, email, pr5_json, data_on]
2074
-
2075
  if result:
2076
- set_clause = ', '.join([f"{col} = ?" for col in columns_to_update])
2077
- query = f"UPDATE contacts SET {set_clause} WHERE email = ? OR phone = ?"
2078
- cursor.execute(query, values_to_update + [email, phone])
 
 
2079
  else:
2080
- query = f"INSERT INTO contacts ({', '.join(columns_to_update)}) VALUES ({', '.join(['?' for _ in columns_to_update])})"
2081
- cursor.execute(query, values_to_update)
 
 
2082
 
2083
  conn.commit()
2084
 
@@ -2121,7 +2121,6 @@ def from_allow():
2121
 
2122
 
2123
 
2124
-
2125
 
2126
 
2127
  @app.route('/gc_in', methods=['GET'])
 
2033
  if api_sys_control != api_key_sys:
2034
  return jsonify({"error": "Unauthorized access"}), 403
2035
 
 
2036
  email = request.args.get('email', '')
2037
  phone = request.args.get('phone', '').lstrip('+')
2038
  module = request.args.get('module', '')
 
2056
  else:
2057
  pr5_data = {}
2058
 
2059
+ if del_flag == '1' and module in pr5_data:
2060
+ del pr5_data[module]
2061
  elif module and status:
2062
  pr5_data[module] = status
2063
 
 
2068
  msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
2069
  data_on = msk_now.strftime('%Y-%m-%d %H:%M:%S')
2070
 
 
 
 
2071
  if result:
2072
+ cursor.execute("""
2073
+ UPDATE contacts
2074
+ SET pr5 = ?, data_on = ?
2075
+ WHERE email = ? OR phone = ?
2076
+ """, (pr5_json, data_on, email, phone))
2077
  else:
2078
+ cursor.execute("""
2079
+ INSERT INTO contacts (email, phone, pr5, data_on)
2080
+ VALUES (?, ?, ?, ?)
2081
+ """, (email, phone, pr5_json, data_on))
2082
 
2083
  conn.commit()
2084
 
 
2121
 
2122
 
2123
 
 
2124
 
2125
 
2126
  @app.route('/gc_in', methods=['GET'])