-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewsapitest.py
More file actions
48 lines (32 loc) · 1.17 KB
/
newsapitest.py
File metadata and controls
48 lines (32 loc) · 1.17 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
import requests
def NewsFromBBC():
# BBC news api
main_url = " https://newsapi.org/v2/everything?q=modi&from=2019-05-18&sortBy=publishedAt&apiKey=d0e27c36e6db402ba8cd7acd29048caf"
# fetching data in json format
open_bbc_page = requests.get(main_url).json()
requests.encoder="utf-8"
# getting all articles in a string article
article = open_bbc_page["articles"]
# empty list which will
# contain all trending news
results = []
source = []
datep = []
urls = []
desc = []
auth=[]
for ar in article:
results.append(ar["title"])
desc.append(ar["description"])
auth.append(ar["author"])
srctemp= ar["source"]
source.append(srctemp["name"])
datep.append(ar["publishedAt"])
urls.append(ar["url"])
for i in range(len(results)):
# printing all trending news
print(i + 1, source[i],'--->', datep[i] ,'--->', auth[i],'\n--->',results[i] )
# Driver Code
if __name__ == '__main__':
# function call
NewsFromBBC()