Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -189,7 +189,71 @@ def get_current_time():
|
|
189 |
def clean_phone_number_ss(phone_number):
|
190 |
return re.sub(r'\D', '', phone_number)
|
191 |
|
192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
# Работа с ордером из сайта без VK_ID
|
194 |
@app.route('/wr_order', methods=['GET'])
|
195 |
def shop_order_new():
|
|
|
189 |
def clean_phone_number_ss(phone_number):
|
190 |
return re.sub(r'\D', '', phone_number)
|
191 |
|
192 |
+
|
193 |
+
|
194 |
+
|
195 |
+
|
196 |
+
# Добавляем пользователя с сайта без VK_ID
|
197 |
+
@app.route('/wr_user', methods=['GET'])
|
198 |
+
def new_wr_user():
|
199 |
+
try:
|
200 |
+
logging.debug("Starting new_wr_user")
|
201 |
+
api_sys_control = request.args.get('api_sys')
|
202 |
+
|
203 |
+
if api_sys_control != api_key_sys:
|
204 |
+
logging.warning("Unauthorized access attempt")
|
205 |
+
return json.dumps({"error": "Unauthorized access"}), 403
|
206 |
+
|
207 |
+
name = request.args.get('name', '')
|
208 |
+
email = request.args.get('email', '')
|
209 |
+
phone = request.args.get('phone', '').lstrip('+')
|
210 |
+
|
211 |
+
if not email or not phone:
|
212 |
+
logging.error("Email and phone are required")
|
213 |
+
return json.dumps({"error": "Email and phone are required"}), 400
|
214 |
+
|
215 |
+
phone = clean_phone_number_ss(phone)
|
216 |
+
|
217 |
+
conn = sqlite3.connect(DATABASE_NEW)
|
218 |
+
cursor = conn.cursor()
|
219 |
+
|
220 |
+
cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
221 |
+
result = cursor.fetchone()
|
222 |
+
|
223 |
+
if result:
|
224 |
+
logging.warning("User already exists")
|
225 |
+
return json.dumps({"error": "User already exists"}), 409
|
226 |
+
|
227 |
+
utc_now = datetime.utcnow()
|
228 |
+
msk_tz = pytz.timezone('Europe/Moscow')
|
229 |
+
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
230 |
+
data_on = msk_now.strftime('%Y-%m-%d %H:%M:%S')
|
231 |
+
|
232 |
+
columns_to_insert = ['name', 'phone', 'email', 'data_on']
|
233 |
+
values_to_insert = [name, phone, email, data_on]
|
234 |
+
|
235 |
+
query = f"INSERT INTO contacts ({', '.join(columns_to_insert)}) VALUES ({', '.join(['?' for _ in columns_to_insert])})"
|
236 |
+
cursor.execute(query, values_to_insert)
|
237 |
+
|
238 |
+
conn.commit()
|
239 |
+
|
240 |
+
replace_null_with_empty_string(conn)
|
241 |
+
|
242 |
+
conn.close()
|
243 |
+
|
244 |
+
return json.dumps({"message": "User added successfully"}), 201
|
245 |
+
|
246 |
+
except Exception as e:
|
247 |
+
logging.error(f"An error occurred: {str(e)}")
|
248 |
+
return json.dumps({"error": str(e)}), 500
|
249 |
+
|
250 |
+
|
251 |
+
|
252 |
+
|
253 |
+
|
254 |
+
|
255 |
+
|
256 |
+
|
257 |
# Работа с ордером из сайта без VK_ID
|
258 |
@app.route('/wr_order', methods=['GET'])
|
259 |
def shop_order_new():
|