Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ from dash import dcc, html, Input, Output
|
|
3 |
import plotly.graph_objs as go
|
4 |
import requests
|
5 |
from datetime import datetime, timedelta
|
|
|
6 |
from weather_model import get_weather_data
|
7 |
|
8 |
# Initialize Dash app
|
@@ -12,6 +13,24 @@ app.title = "Weather Forecast Dashboard"
|
|
12 |
# API Key for OpenWeatherMap (replace with your own)
|
13 |
API_KEY = "53d50455f91b6bc3c920959e2954576d"
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
# Layout with advanced UI
|
16 |
app.layout = html.Div([
|
17 |
html.Div([
|
|
|
3 |
import plotly.graph_objs as go
|
4 |
import requests
|
5 |
from datetime import datetime, timedelta
|
6 |
+
from flask import Flask, render_template, request, jsonify
|
7 |
from weather_model import get_weather_data
|
8 |
|
9 |
# Initialize Dash app
|
|
|
13 |
# API Key for OpenWeatherMap (replace with your own)
|
14 |
API_KEY = "53d50455f91b6bc3c920959e2954576d"
|
15 |
|
16 |
+
@app.route('/')
|
17 |
+
def index():
|
18 |
+
return render_template('index.html')
|
19 |
+
|
20 |
+
@app.route('/weather', methods=['GET'])
|
21 |
+
def weather():
|
22 |
+
city = request.args.get('city')
|
23 |
+
days = int(request.args.get('days', 5))
|
24 |
+
|
25 |
+
if not city:
|
26 |
+
return jsonify({'error': 'Please provide a city name'}), 400
|
27 |
+
|
28 |
+
weather_data = get_weather_data(city, days, API_KEY)
|
29 |
+
if not weather_data:
|
30 |
+
return jsonify({'error': 'City not found or API error'}), 404
|
31 |
+
|
32 |
+
return jsonify(weather_data)
|
33 |
+
|
34 |
# Layout with advanced UI
|
35 |
app.layout = html.Div([
|
36 |
html.Div([
|