Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -90,32 +90,41 @@ def get_date_panchang(date: str = None) -> str:
|
|
| 90 |
"""
|
| 91 |
|
| 92 |
if not date:
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
| 100 |
|
| 101 |
try:
|
| 102 |
-
|
| 103 |
-
f"https://
|
| 104 |
-
|
| 105 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
response.raise_for_status()
|
| 107 |
data = response.json()
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 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(
|
| 117 |
lines.append(f"🔹 {key}: {', '.join(value)}")
|
| 118 |
-
elif all(isinstance(
|
| 119 |
lines.append(f"🔹 {key}:")
|
| 120 |
for item in value:
|
| 121 |
vals = item.get("values", [])
|
|
@@ -125,13 +134,11 @@ def get_date_panchang(date: str = None) -> 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 {
|
| 135 |
|
| 136 |
@tool
|
| 137 |
def get_holidays(year: int = None, date: str = None) -> str:
|
|
|
|
| 90 |
"""
|
| 91 |
|
| 92 |
if not date:
|
| 93 |
+
now = datetime.datetime.now()
|
| 94 |
+
else:
|
| 95 |
+
try:
|
| 96 |
+
now = datetime.datetime.strptime(date, "%Y-%m-%d")
|
| 97 |
+
except ValueError:
|
| 98 |
+
return "❌ Invalid date format. Use YYYY-MM-DD."
|
| 99 |
+
|
| 100 |
+
api_date = now.strftime("%d/%m/%y") # Format as DD/MM/YY
|
| 101 |
|
| 102 |
try:
|
| 103 |
+
url = (
|
| 104 |
+
f"https://api.exaweb.in:3004/api/panchang/daily?"
|
| 105 |
+
f"date={api_date}&app_language={app_language}&data_language={data_language}"
|
| 106 |
)
|
| 107 |
+
|
| 108 |
+
headers = {
|
| 109 |
+
"Authorization": "anvl_bharat_cal123", # 🔁 Replace with your actual token
|
| 110 |
+
"Content-Type": "application/json"
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
response = requests.get(url, headers=headers)
|
| 114 |
response.raise_for_status()
|
| 115 |
data = response.json()
|
| 116 |
|
| 117 |
+
if not data or not isinstance(data, dict):
|
| 118 |
+
return "⚠️ Empty or unexpected response."
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
# Format the entire Panchang data nicely
|
| 121 |
+
lines = [f"📅 {data.get('date', api_date)} का पंचांग ({data.get('location', 'Unknown')}):\n"]
|
| 122 |
+
|
| 123 |
+
for key, value in data.items():
|
| 124 |
if isinstance(value, list):
|
| 125 |
+
if all(isinstance(item, str) for item in value):
|
| 126 |
lines.append(f"🔹 {key}: {', '.join(value)}")
|
| 127 |
+
elif all(isinstance(item, dict) for item in value):
|
| 128 |
lines.append(f"🔹 {key}:")
|
| 129 |
for item in value:
|
| 130 |
vals = item.get("values", [])
|
|
|
|
| 134 |
lines.append(f"🔹 {key}: {value}")
|
| 135 |
elif isinstance(value, int):
|
| 136 |
lines.append(f"🔹 {key}: {value}")
|
|
|
|
|
|
|
| 137 |
|
| 138 |
return "\n".join(lines)
|
| 139 |
|
| 140 |
except Exception as e:
|
| 141 |
+
return f"❌ Failed to fetch Panchang for {api_date}: {str(e)}"
|
| 142 |
|
| 143 |
@tool
|
| 144 |
def get_holidays(year: int = None, date: str = None) -> str:
|