-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbusiness_news_reader.py
35 lines (25 loc) · 1.06 KB
/
business_news_reader.py
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
import requests
from bs4 import BeautifulSoup
import tts
# NDTV News
fixed_url = 'http://profit.ndtv.com/news/latest/'
news_headlines_list = []
news_details_list = []
for i in range(1, 2):
changing_slug = '/page-' + str(i)
url = fixed_url + changing_slug
r = requests.get(url)
data = r.text
soup = BeautifulSoup(data, "html.parser")
for news_headlines in soup.find_all('h2'):
news_headlines_list.append(news_headlines.get_text())
del news_headlines_list[-2:]
for news_details in soup.find_all('p', 'intro'):
news_details_list.append(news_details.get_text())
news_headlines_list_small = [element.lower().replace("(", "").replace(")","").replace("'", "") for element in news_headlines_list]
news_details_list_small = [element.lower().replace("(", "").replace(")","").replace("'", "") for element in news_details_list]
news_dictionary = dict(zip(news_headlines_list_small, news_details_list_small))
def news_reader():
for key, value in news_dictionary.items():
tts('Headline, ' + key)
tts('News, ' + value)