Spaces:
Sleeping
Sleeping
Shageenderan Sapai commited on
Commit ·
4908d19
1
Parent(s): 8efacba
Added db querry for user subscribtion
Browse files
app/__pycache__/assistants.cpython-312.pyc
CHANGED
|
Binary files a/app/__pycache__/assistants.cpython-312.pyc and b/app/__pycache__/assistants.cpython-312.pyc differ
|
|
|
app/__pycache__/main.cpython-312.pyc
CHANGED
|
Binary files a/app/__pycache__/main.cpython-312.pyc and b/app/__pycache__/main.cpython-312.pyc differ
|
|
|
app/__pycache__/user.cpython-312.pyc
CHANGED
|
Binary files a/app/__pycache__/user.cpython-312.pyc and b/app/__pycache__/user.cpython-312.pyc differ
|
|
|
app/__pycache__/utils.cpython-312.pyc
CHANGED
|
Binary files a/app/__pycache__/utils.cpython-312.pyc and b/app/__pycache__/utils.cpython-312.pyc differ
|
|
|
app/assistants.py
CHANGED
|
@@ -660,6 +660,7 @@ class Assistant:
|
|
| 660 |
# "growth_guide_session",
|
| 661 |
# "life_score",
|
| 662 |
# "recent_wins",
|
|
|
|
| 663 |
# ]
|
| 664 |
logger.info(f"Getting user information: {category}",
|
| 665 |
extra={"user_id": self.cm.user.user_id, "endpoint": "assistant_get_user_info"})
|
|
|
|
| 660 |
# "growth_guide_session",
|
| 661 |
# "life_score",
|
| 662 |
# "recent_wins",
|
| 663 |
+
# "subscription/payments"
|
| 664 |
# ]
|
| 665 |
logger.info(f"Getting user information: {category}",
|
| 666 |
extra={"user_id": self.cm.user.user_id, "endpoint": "assistant_get_user_info"})
|
app/requirements.txt
CHANGED
|
@@ -14,4 +14,5 @@ regex==2024.9.11
|
|
| 14 |
Requests==2.32.3
|
| 15 |
cachetools>=5.0.0
|
| 16 |
pdfkit==1.0.0
|
| 17 |
-
PyPDF2==3.0.1
|
|
|
|
|
|
| 14 |
Requests==2.32.3
|
| 15 |
cachetools>=5.0.0
|
| 16 |
pdfkit==1.0.0
|
| 17 |
+
PyPDF2==3.0.1
|
| 18 |
+
sentry-sdk==2.19.2
|
app/utils.py
CHANGED
|
@@ -1393,6 +1393,58 @@ def get_users_mementos(user_id, date):
|
|
| 1393 |
finally:
|
| 1394 |
return mementos
|
| 1395 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1396 |
def generate_uuid():
|
| 1397 |
return str(uuid.uuid4())
|
| 1398 |
|
|
|
|
| 1393 |
finally:
|
| 1394 |
return mementos
|
| 1395 |
|
| 1396 |
+
@catch_error
|
| 1397 |
+
def get_user_subscriptions(user_id):
|
| 1398 |
+
function_name = get_user_subscriptions.__name__
|
| 1399 |
+
logger.info(f"Retrieving subscriptions for user {user_id}", extra={'endpoint': function_name})
|
| 1400 |
+
db_params = {
|
| 1401 |
+
'dbname': 'ourcoach',
|
| 1402 |
+
'user': 'ourcoach',
|
| 1403 |
+
'password': 'hvcTL3kN3pOG5KteT17T',
|
| 1404 |
+
'host': 'staging-ourcoach.cx8se8o0iaiy.ap-southeast-1.rds.amazonaws.com',
|
| 1405 |
+
'port': '5432'
|
| 1406 |
+
}
|
| 1407 |
+
try:
|
| 1408 |
+
with psycopg2.connect(**db_params) as conn:
|
| 1409 |
+
with conn.cursor() as cursor:
|
| 1410 |
+
query = sql.SQL("""
|
| 1411 |
+
SELECT * FROM {table}
|
| 1412 |
+
WHERE user_id = %s
|
| 1413 |
+
ORDER BY period_started DESC
|
| 1414 |
+
""").format(table=sql.Identifier('public', 'user_subscription'))
|
| 1415 |
+
cursor.execute(query, (user_id,))
|
| 1416 |
+
rows = cursor.fetchall()
|
| 1417 |
+
colnames = [desc[0] for desc in cursor.description]
|
| 1418 |
+
df = pd.DataFrame(rows, columns=colnames)
|
| 1419 |
+
logger.info(f"Retrieved {len(df)} subscriptions for user {user_id}", extra={'endpoint': function_name})
|
| 1420 |
+
return df
|
| 1421 |
+
except psycopg2.Error as e:
|
| 1422 |
+
logger.error(f"Database error while retrieving user subscriptions: {e}", extra={'endpoint': function_name})
|
| 1423 |
+
raise DBError(user_id=user_id, message="Error retrieving user subscriptions", code="SQLError", e=str(e))
|
| 1424 |
+
def get_user_subscriptions():
|
| 1425 |
+
function_name = get_user_subscriptions.__name__
|
| 1426 |
+
logger.info(f"Retrieving all user subscriptions", extra={'endpoint': function_name})
|
| 1427 |
+
db_params = {
|
| 1428 |
+
'dbname': 'ourcoach',
|
| 1429 |
+
'user': 'ourcoach',
|
| 1430 |
+
'password': 'hvcTL3kN3pOG5KteT17T',
|
| 1431 |
+
'host': 'staging-ourcoach.cx8se8o0iaiy.ap-southeast-1.rds.amazonaws.com',
|
| 1432 |
+
'port': '5432'
|
| 1433 |
+
}
|
| 1434 |
+
try:
|
| 1435 |
+
with psycopg2.connect(**db_params) as conn:
|
| 1436 |
+
with conn.cursor() as cursor:
|
| 1437 |
+
query = sql.SQL("SELECT * FROM {table}").format(table=sql.Identifier('public', 'user_subscription'))
|
| 1438 |
+
cursor.execute(query)
|
| 1439 |
+
rows = cursor.fetchall()
|
| 1440 |
+
colnames = [desc[0] for desc in cursor.description]
|
| 1441 |
+
df = pd.DataFrame(rows, columns=colnames)
|
| 1442 |
+
logger.info(f"Retrieved {len(df)} user subscriptions", extra={'endpoint': function_name})
|
| 1443 |
+
return df
|
| 1444 |
+
except psycopg2.Error as e:
|
| 1445 |
+
logger.error(f"Database error while retrieving user subscriptions: {e}", extra={'endpoint': function_name})
|
| 1446 |
+
raise DBError(user_id='no-user', message="Error retrieving user subscriptions", code="SQLError", e=str(e))
|
| 1447 |
+
|
| 1448 |
def generate_uuid():
|
| 1449 |
return str(uuid.uuid4())
|
| 1450 |
|