Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -88,9 +88,50 @@ def get_date_panchang(date: str = None) -> str:
|
|
| 88 |
Args:
|
| 89 |
date: Date in any format (optional)
|
| 90 |
"""
|
|
|
|
| 91 |
if not date:
|
| 92 |
-
date = datetime.now().strftime("%Y-%m-%d")
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
@tool
|
| 96 |
def get_holidays(year: int = None, date: str = None) -> str:
|
|
|
|
| 88 |
Args:
|
| 89 |
date: Date in any format (optional)
|
| 90 |
"""
|
| 91 |
+
|
| 92 |
if not date:
|
| 93 |
+
date = datetime.datetime.now().strftime("%Y-%m-%d")
|
| 94 |
+
|
| 95 |
+
try:
|
| 96 |
+
parsed_date = datetime.datetime.strptime(date, "%Y-%m-%d")
|
| 97 |
+
formatted_date = parsed_date.strftime("%d-%m-%Y")
|
| 98 |
+
except ValueError:
|
| 99 |
+
return "❌ Invalid date format. Use YYYY-MM-DD."
|
| 100 |
+
|
| 101 |
+
try:
|
| 102 |
+
response = requests.get(
|
| 103 |
+
f"https://your-api-url.com/panchang?date={formatted_date}",
|
| 104 |
+
headers={"Authorization": "Bearer YOUR_AUTH_TOKEN"}
|
| 105 |
+
)
|
| 106 |
+
response.raise_for_status()
|
| 107 |
+
data = response.json()
|
| 108 |
+
|
| 109 |
+
# Create formatted output for all key-value pairs
|
| 110 |
+
lines = [f"📅 Panchang for {data.get('date')} ({data.get('location')})", ""]
|
| 111 |
+
for key, value in data.items():
|
| 112 |
+
if key in ['date', 'location', 'universalDate', 'app_language', 'data_language']:
|
| 113 |
+
continue # Already shown or not useful
|
| 114 |
+
|
| 115 |
+
if isinstance(value, list):
|
| 116 |
+
if all(isinstance(i, str) for i in value):
|
| 117 |
+
lines.append(f"🔹 {key}: {', '.join(value)}")
|
| 118 |
+
elif all(isinstance(i, dict) for i in value):
|
| 119 |
+
lines.append(f"🔹 {key}:")
|
| 120 |
+
for item in value:
|
| 121 |
+
vals = item.get("values", [])
|
| 122 |
+
upto = item.get("upto", "")
|
| 123 |
+
lines.append(f" • {', '.join(vals)} {'— ' + upto if upto else ''}")
|
| 124 |
+
elif isinstance(value, str):
|
| 125 |
+
lines.append(f"🔹 {key}: {value}")
|
| 126 |
+
elif isinstance(value, int):
|
| 127 |
+
lines.append(f"🔹 {key}: {value}")
|
| 128 |
+
else:
|
| 129 |
+
lines.append(f"🔹 {key}: {str(value)}")
|
| 130 |
+
|
| 131 |
+
return "\n".join(lines)
|
| 132 |
+
|
| 133 |
+
except Exception as e:
|
| 134 |
+
return f"❌ Failed to fetch Panchang for {formatted_date}: {str(e)}"
|
| 135 |
|
| 136 |
@tool
|
| 137 |
def get_holidays(year: int = None, date: str = None) -> str:
|