-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
104 lines (75 loc) · 2.58 KB
/
views.py
File metadata and controls
104 lines (75 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from flask import Flask,render_template,request,redirect,url_for
# from app import app
from newsapi import NewsApiClient
app =Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
# bcc news page
@app.route('/bbc')
def bbc():
newapi = NewsApiClient(api_key="7497b8a3477240c181b4b85f120d9d24")
topheadlines = newapi.get_top_headlines(sources="bbc-news")
articles = topheadlines['articles']
news = []
description = []
link = []
image = []
time = []
content = []
for i in range(len(articles)):
myarticles = articles [i]
news.append(myarticles['title'])
description.append(myarticles['description'])
link.append(myarticles['url'])
image.append(myarticles['urlToImage'])
time.append(myarticles['publishedAt'])
content.append(myarticles ['content'])
my_list = zip( news,description,link,image,time,content)
return render_template('bbc.html',context=my_list)
# cnn news page
@app.route('/cnn')
def cnn():
newapi = NewsApiClient(api_key="7497b8a3477240c181b4b85f120d9d24")
topheadlines = newapi.get_top_headlines(sources="CBC-News")
articles = topheadlines['articles']
news = []
description = []
link = []
image = []
time = []
content = []
for i in range(len(articles)):
myarticles = articles [i]
news.append(myarticles['title'])
description.append(myarticles['description'])
link.append(myarticles['url'])
image.append(myarticles['urlToImage'])
time.append(myarticles['publishedAt'])
content.append(myarticles ['content'])
my_list = zip( news,description,link,image,time,content)
return render_template('cnn.html',context=my_list)
# google news
@app.route('/google')
def google():
newapi = NewsApiClient(api_key="7497b8a3477240c181b4b85f120d9d24")
topheadlines = newapi.get_top_headlines(sources="google-news")
articles = topheadlines['articles']
news = []
description = []
link = []
image = []
time = []
content = []
for i in range(len(articles)):
myarticles = articles [i]
news.append(myarticles['title'])
description.append(myarticles['description'])
link.append(myarticles['url'])
image.append(myarticles['urlToImage'])
time.append(myarticles['publishedAt'])
content.append(myarticles ['content'])
my_list = zip( news,description,link,image,time,content)
return render_template('google.html',context=my_list)
if __name__=='__main__':
app.run (debug = True)