from datetime import datetime
def format_date(date_string):
"""Convert database date to readable format"""
if not date_string:
return "N/A"
try:
# If date_string is already a datetime object
if isinstance(date_string, datetime):
return date_string.strftime("%d %b %Y, %H:%M")
# If it's a string, parse it first
date_obj = datetime.strptime(str(date_string), "%Y-%m-%d %H:%M:%S")
return date_obj.strftime("%d %b %Y, %H:%M")
except:
return str(date_string)
def calculate_age(birthday_string):
"""Calculate age from birthday"""
if not birthday_string:
return "N/A"
try:
birth_date = datetime.strptime(str(birthday_string), "%Y-%m-%d").date()
today = datetime.now().date()
age = today.year - birth_date.year - \
((today.month, today.day) < (birth_date.month, birth_date.day))
return age
except:
return "N/A"
# Student Info Formatter
def format_student_info(student):
"""
Format student data into a nice message
student is a tuple: (id, username, name, created_at, email, phone_number, last_seen, is_verified, birthday)
"""
print(student)
id, username, name, created_at, email, phone_number, last_seen, is_verfied, birthday = student
verified_status = "✅ Verified" if is_verfied else "❌ Not Verified"
# Format dates nicely
created_date = format_date(created_at)
last_seen_date = format_date(last_seen)
# Calculate age from birthday
age = calculate_age(birthday)
details = f"""
👤 Student Profile
Name: {name}
Username: {username}
Email: {email}
Phone: {phone_number}
Birthday: {birthday} (Age: {age})
Account Status: {verified_status}
📅 Account Info
Joined: {created_date}
Last Seen: {last_seen_date}
ID: {id}
"""
return details.strip()
# Teacher Info Formatter
def format_teacher_info(teacher):
"""
Format student data into a nice message
student is a tuple: (id, username, created_at, email, phone_number, last_seen, is_verified, birthday)
"""
print(teacher)
id, username, name, created_at, email, phone_number, last_seen, is_verfied, birthday, about_me, job_title = teacher
verified_status = "✅ Verified" if is_verfied else "❌ Not Verified"
# Format dates nicely
created_date = format_date(created_at)
last_seen_date = format_date(last_seen)
# Calculate age from birthday
age = calculate_age(birthday)
details = f"""
👤 Teacher Profile
Name: {name}
Username: {username}
Job Title: {job_title}
About Me: {about_me}
Email: {email}
Phone: {phone_number}
Birthday: {birthday} (Age: {age})
Account Status: {verified_status}
📅 Account Info
Joined: {created_date}
Last Seen: {last_seen_date}
ID: {id}
"""
return details.strip()