Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -194,7 +194,43 @@ mapping_template = {
|
|
194 |
|
195 |
|
196 |
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
|
200 |
|
|
|
194 |
|
195 |
|
196 |
|
197 |
+
def get_db_connection_user():
|
198 |
+
DATABASE_NEW = 'data_gc.db'
|
199 |
+
conn = sqlite3.connect(DATABASE_NEW)
|
200 |
+
conn.row_factory = sqlite3.Row
|
201 |
+
return conn
|
202 |
+
|
203 |
+
@app.route('/user_db', methods=['GET'])
|
204 |
+
def get_user():
|
205 |
+
email = request.args.get('email')
|
206 |
+
vk_id = request.args.get('vk_id')
|
207 |
+
|
208 |
+
if not email and not vk_id:
|
209 |
+
return jsonify({"error": "Either email or vk_id must be provided"}), 400
|
210 |
+
|
211 |
+
conn = get_db_connection()
|
212 |
+
cursor = conn.cursor()
|
213 |
+
|
214 |
+
query = "SELECT * FROM contacts WHERE "
|
215 |
+
params = []
|
216 |
+
|
217 |
+
if email:
|
218 |
+
query += "email = ?"
|
219 |
+
params.append(email)
|
220 |
+
if email and vk_id:
|
221 |
+
query += " OR "
|
222 |
+
if vk_id:
|
223 |
+
query += "vk_id = ?"
|
224 |
+
params.append(vk_id)
|
225 |
+
|
226 |
+
cursor.execute(query, params)
|
227 |
+
user = cursor.fetchone()
|
228 |
+
conn.close()
|
229 |
+
|
230 |
+
if user:
|
231 |
+
return jsonify(dict(user))
|
232 |
+
else:
|
233 |
+
return jsonify({"error": "User not found"}), 404
|
234 |
|
235 |
|
236 |
|