Skip to content

Commit 24df001

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 15d59c1 commit 24df001

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

web_programming/Global Events Tracker.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
app = Flask(__name__)
55

66
# 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+
)
810
NEWS_API_URL = "https://gnews.io/api/v4/top-headlines?token=YOUR_API_KEY&lang=en" # Replace with your API key
911

1012
# Base HTML template
@@ -96,11 +98,13 @@
9698
{% endblock %}
9799
"""
98100

99-
@app.route('/')
101+
102+
@app.route("/")
100103
def index():
101104
return render_template_string(BASE_TEMPLATE + INDEX_TEMPLATE)
102105

103-
@app.route('/covid-stats')
106+
107+
@app.route("/covid-stats")
104108
def covid_stats():
105109
# Fetch COVID-19 stats from the public API
106110
try:
@@ -109,20 +113,24 @@ def covid_stats():
109113
except requests.exceptions.RequestException as e:
110114
covid_data = []
111115
print(f"Error fetching COVID data: {e}")
112-
116+
113117
return render_template_string(BASE_TEMPLATE + COVID_TEMPLATE, covid_data=covid_data)
114118

115-
@app.route('/news')
119+
120+
@app.route("/news")
116121
def global_news():
117122
# Fetch global news using GNews API
118123
try:
119124
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+
)
121128
except requests.exceptions.RequestException as e:
122129
news_data = []
123130
print(f"Error fetching news data: {e}")
124-
131+
125132
return render_template_string(BASE_TEMPLATE + NEWS_TEMPLATE, news_data=news_data)
126133

127-
if __name__ == '__main__':
134+
135+
if __name__ == "__main__":
128136
app.run(debug=True)

0 commit comments

Comments
 (0)