Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -158,6 +158,24 @@ async def youtube_transcript(
|
|
| 158 |
return JSONResponse(content=jsonable_encoder(transcript))
|
| 159 |
except Exception as e:
|
| 160 |
raise HTTPException(status_code=500, detail=f"Error getting YouTube transcript: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
# Run the API server if this script is executed
|
| 163 |
if __name__ == "__main__":
|
|
|
|
| 158 |
return JSONResponse(content=jsonable_encoder(transcript))
|
| 159 |
except Exception as e:
|
| 160 |
raise HTTPException(status_code=500, detail=f"Error getting YouTube transcript: {e}")
|
| 161 |
+
import requests
|
| 162 |
+
@app.get("/weather/json/{location}")
|
| 163 |
+
def get_weather_json(location: str):
|
| 164 |
+
url = f"https://wttr.in/{location}?format=j1"
|
| 165 |
+
response = requests.get(url)
|
| 166 |
+
if response.status_code == 200:
|
| 167 |
+
return response.json()
|
| 168 |
+
else:
|
| 169 |
+
return {"error": f"Unable to fetch weather data. Status code: {response.status_code}"}
|
| 170 |
+
|
| 171 |
+
@app.get("/weather/ascii/{location}")
|
| 172 |
+
def get_ascii_weather(location: str):
|
| 173 |
+
url = f"https://wttr.in/{location}"
|
| 174 |
+
response = requests.get(url, headers={'User-Agent': 'curl'})
|
| 175 |
+
if response.status_code == 200:
|
| 176 |
+
return response.text
|
| 177 |
+
else:
|
| 178 |
+
return {"error": f"Unable to fetch weather data. Status code: {response.status_code}"}
|
| 179 |
|
| 180 |
# Run the API server if this script is executed
|
| 181 |
if __name__ == "__main__":
|