File tree 1 file changed +16
-8
lines changed
1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change 4
4
app = Flask (__name__ )
5
5
6
6
# Public APIs for real-time global data (you can replace or add more as needed)
7
- COVID_API_URL = "https://disease.sh/v3/covid-19/countries" # Get COVID-19 stats by country
7
+ COVID_API_URL = (
8
+ "https://disease.sh/v3/covid-19/countries" # Get COVID-19 stats by country
9
+ )
8
10
NEWS_API_URL = "https://gnews.io/api/v4/top-headlines?token=YOUR_API_KEY&lang=en" # Replace with your API key
9
11
10
12
# Base HTML template
96
98
{% endblock %}
97
99
"""
98
100
99
- @app .route ('/' )
101
+
102
+ @app .route ("/" )
100
103
def index ():
101
104
return render_template_string (BASE_TEMPLATE + INDEX_TEMPLATE )
102
105
103
- @app .route ('/covid-stats' )
106
+
107
+ @app .route ("/covid-stats" )
104
108
def covid_stats ():
105
109
# Fetch COVID-19 stats from the public API
106
110
try :
@@ -109,20 +113,24 @@ def covid_stats():
109
113
except requests .exceptions .RequestException as e :
110
114
covid_data = []
111
115
print (f"Error fetching COVID data: { e } " )
112
-
116
+
113
117
return render_template_string (BASE_TEMPLATE + COVID_TEMPLATE , covid_data = covid_data )
114
118
115
- @app .route ('/news' )
119
+
120
+ @app .route ("/news" )
116
121
def global_news ():
117
122
# Fetch global news using GNews API
118
123
try :
119
124
response = requests .get (NEWS_API_URL )
120
- news_data = response .json ().get ('articles' , []) if response .status_code == 200 else []
125
+ news_data = (
126
+ response .json ().get ("articles" , []) if response .status_code == 200 else []
127
+ )
121
128
except requests .exceptions .RequestException as e :
122
129
news_data = []
123
130
print (f"Error fetching news data: { e } " )
124
-
131
+
125
132
return render_template_string (BASE_TEMPLATE + NEWS_TEMPLATE , news_data = news_data )
126
133
127
- if __name__ == '__main__' :
134
+
135
+ if __name__ == "__main__" :
128
136
app .run (debug = True )
You can’t perform that action at this time.
0 commit comments