Spaces:
Runtime error
Runtime error
| # utils/helpers.py | |
| """ | |
| Helper utility functions | |
| """ | |
| import json | |
| import os | |
| import random | |
| from datetime import datetime | |
| from zoneinfo import ZoneInfo | |
| def load_quotes(): | |
| """Load inspirational quotes from Gita/Vedas""" | |
| quotes_file = 'data/quotes.json' | |
| default_quotes = [ | |
| "विद्या ददाति विनयं - Knowledge gives humility", | |
| "योग: कर्मसु कौशलम् - Yoga is skill in action", | |
| "श्रेयान्स्वधर्मो विगुण: - Better is one's own dharma though imperfectly performed", | |
| "कर्मण्येवाधिकारस्ते - You have the right to perform action", | |
| "विद्या धनं सर्व धन प्रधानम् - Knowledge is the supreme wealth", | |
| "सत्यमेव जयते - Truth alone triumphs", | |
| "तमसो मा ज्योतिर्गमय - Lead me from darkness to light", | |
| "अहिंसा परमो धर्म: - Non-violence is the supreme virtue" | |
| ] | |
| if not os.path.exists(quotes_file): | |
| os.makedirs('data', exist_ok=True) | |
| with open(quotes_file, 'w', encoding='utf-8') as f: | |
| json.dump(default_quotes, f, indent=2, ensure_ascii=False) | |
| return default_quotes | |
| try: | |
| with open(quotes_file, 'r', encoding='utf-8') as f: | |
| return json.load(f) | |
| except: | |
| return default_quotes | |
| def get_greeting(): | |
| """ | |
| Returns a time-of-day appropriate greeting in English and Hindi, | |
| specifically for the Indian Standard Time (IST) timezone. | |
| """ | |
| # Define the Indian Standard Time timezone | |
| ist_timezone = ZoneInfo("Asia/Kolkata") | |
| # Get the current time in the IST timezone | |
| current_time_ist = datetime.now(ist_timezone) | |
| current_hour = current_time_ist.hour | |
| if 5 <= current_hour < 12: | |
| return "☀️ सुप्रभात (Good Morning)! Ready to start the day?" | |
| elif 12 <= current_hour < 17: | |
| return "☀️ नमस्कार (Good Afternoon)! Time for a study session?" | |
| elif 17 <= current_hour < 21: | |
| return "🌇 शुभ संध्या (Good Evening)! Wrapping up your studies?" | |
| else: | |
| return "🌙 शुभ रात्रि (Good Night)! Late night study session?" | |
| def format_indian_text(text, add_emojis=True): | |
| """Format text with Indian cultural elements""" | |
| if add_emojis: | |
| # Add relevant emojis based on content | |
| if any(word in text.lower() for word in ['drug', 'medicine', 'pharmaceutical']): | |
| text = f"💊 {text}" | |
| elif any(word in text.lower() for word in ['study', 'learn', 'education']): | |
| text = f"📚 {text}" | |
| elif any(word in text.lower() for word in ['quiz', 'test', 'exam']): | |
| text = f"❓ {text}" | |
| elif any(word in text.lower() for word in ['memory', 'remember', 'mnemonic']): | |
| text = f"🧠 {text}" | |
| return text |