Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -387,56 +387,26 @@ def update_user_limit(uid):
|
|
| 387 |
|
| 388 |
|
| 389 |
# User management endpoint for profile
|
| 390 |
-
@app.route('/api/user/
|
| 391 |
-
def
|
| 392 |
try:
|
| 393 |
uid = verify_token(request.headers.get('Authorization', '').split(' ')[1])
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
if transactions is None:
|
| 398 |
-
return jsonify({
|
| 399 |
-
'daily_spending': [],
|
| 400 |
-
'recent_transactions': []
|
| 401 |
-
})
|
| 402 |
-
|
| 403 |
-
# Create dataframe
|
| 404 |
-
df = pd.DataFrame.from_dict(transactions, orient='index')
|
| 405 |
-
|
| 406 |
-
# Check if dataframe is empty
|
| 407 |
-
if df.empty:
|
| 408 |
-
return jsonify({
|
| 409 |
-
'daily_spending': [],
|
| 410 |
-
'recent_transactions': []
|
| 411 |
-
})
|
| 412 |
-
|
| 413 |
-
# Check if all the data is here, otherwise we delete the data.
|
| 414 |
-
df.dropna(subset=['uid','total','items','date', 'receipt_number', 'timestamp','hash', 'manual_entry'], inplace=True)
|
| 415 |
-
if df.empty:
|
| 416 |
-
return jsonify({
|
| 417 |
-
'daily_spending': [],
|
| 418 |
-
'recent_transactions': []
|
| 419 |
-
})
|
| 420 |
|
| 421 |
-
df['date'] = pd.to_datetime(df['date'], format='%d/%m/%Y', errors='coerce')
|
| 422 |
-
df.dropna(subset=['date'], inplace=True)
|
| 423 |
-
if df.empty:
|
| 424 |
-
return jsonify({
|
| 425 |
-
'daily_spending': [],
|
| 426 |
-
'recent_transactions': []
|
| 427 |
-
})
|
| 428 |
-
|
| 429 |
-
daily_spending = df.groupby(df['date'].dt.date)['total'].sum().reset_index()
|
| 430 |
-
|
| 431 |
return jsonify({
|
| 432 |
-
'
|
| 433 |
-
'
|
| 434 |
-
|
| 435 |
-
|
|
|
|
|
|
|
| 436 |
})
|
| 437 |
except Exception as e:
|
| 438 |
-
|
| 439 |
-
|
|
|
|
|
|
|
| 440 |
|
| 441 |
# Receipt media endpoints
|
| 442 |
|
|
@@ -579,4 +549,4 @@ def delete_user(uid):
|
|
| 579 |
|
| 580 |
|
| 581 |
if __name__ == '__main__':
|
| 582 |
-
app.run(debug=True, host="0.0.0.0", port=7860)
|
|
|
|
| 387 |
|
| 388 |
|
| 389 |
# User management endpoint for profile
|
| 390 |
+
@app.route('/api/user/profile', methods=['GET'])
|
| 391 |
+
def get_user_profile():
|
| 392 |
try:
|
| 393 |
uid = verify_token(request.headers.get('Authorization', '').split(' ')[1])
|
| 394 |
+
user = auth.get_user(uid)
|
| 395 |
+
user_data = db.reference(f'users/{uid}').get()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
return jsonify({
|
| 398 |
+
'uid': uid,
|
| 399 |
+
'email': user.email,
|
| 400 |
+
'daily_cash': user_data.get('daily_cash', 0),
|
| 401 |
+
'remaining_cash': user_data.get('remaining_cash', 0),
|
| 402 |
+
'last_reset': user_data.get('last_reset'),
|
| 403 |
+
'is_admin': user_data.get('is_admin', False)
|
| 404 |
})
|
| 405 |
except Exception as e:
|
| 406 |
+
uid = verify_token(request.headers.get('Authorization', '').split(' ')[1])
|
| 407 |
+
user = auth.get_user(uid)
|
| 408 |
+
user_data = db.reference(f'users/{uid}').get()
|
| 409 |
+
return jsonify({'error': str(e)+ f'user data: {user_data}'}), 500
|
| 410 |
|
| 411 |
# Receipt media endpoints
|
| 412 |
|
|
|
|
| 549 |
|
| 550 |
|
| 551 |
if __name__ == '__main__':
|
| 552 |
+
app.run(debug=True, host="0.0.0.0", port=7860)
|