Update app.py
Browse files
app.py
CHANGED
|
@@ -2025,7 +2025,71 @@ def from_shop_st3():
|
|
| 2025 |
except Exception as e:
|
| 2026 |
return json.dumps({"error": str(e)}), 500
|
| 2027 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2028 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
|
|
|
| 2025 |
except Exception as e:
|
| 2026 |
return json.dumps({"error": str(e)}), 500
|
| 2027 |
|
| 2028 |
+
@app.route('/allow', methods=['GET'])
|
| 2029 |
+
def from_allow():
|
| 2030 |
+
try:
|
| 2031 |
+
api_sys_control = request.args.get('api_sys')
|
| 2032 |
+
|
| 2033 |
+
if api_sys_control != api_key_sys:
|
| 2034 |
+
return json.dumps({"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', '') # Заменяем на "module"
|
| 2040 |
+
status = request.args.get('status', '')
|
| 2041 |
+
del_flag = request.args.get('del', '')
|
| 2042 |
+
|
| 2043 |
+
if not email or not phone:
|
| 2044 |
+
return json.dumps({"error": "Email and phone are required"}), 400
|
| 2045 |
+
|
| 2046 |
+
phone = clean_phone_number_ss(phone)
|
| 2047 |
|
| 2048 |
+
conn = sqlite3.connect(DATABASE6)
|
| 2049 |
+
cursor = conn.cursor()
|
| 2050 |
+
|
| 2051 |
+
cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
| 2052 |
+
result = cursor.fetchone()
|
| 2053 |
+
|
| 2054 |
+
if result:
|
| 2055 |
+
pr5 = result[17] if result[17] else '{}'
|
| 2056 |
+
pr5_data = json.loads(pr5)
|
| 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 |
+
|
| 2065 |
+
pr5_json = json.dumps(pr5_data)
|
| 2066 |
+
|
| 2067 |
+
utc_now = datetime.utcnow()
|
| 2068 |
+
msk_tz = pytz.timezone('Europe/Moscow')
|
| 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 |
+
|
| 2085 |
+
replace_null_with_empty_string(conn)
|
| 2086 |
+
|
| 2087 |
+
conn.close()
|
| 2088 |
+
|
| 2089 |
+
return json.dumps(pr5_data), 200
|
| 2090 |
+
|
| 2091 |
+
except Exception as e:
|
| 2092 |
+
return json.dumps({"error": str(e)}), 500
|
| 2093 |
|
| 2094 |
|
| 2095 |
|