-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent.py
168 lines (158 loc) · 7.96 KB
/
content.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# Read newspaper with python
# using two important and popular python pacakages requests and json
import requests
import json
# color settings
from colored import fg, bg, attr
reset = attr('reset')
# function for speech
def speak(str):
from win32com.client import Dispatch
speak = Dispatch("SAPI.SpVoice")
speak.speak(str)
# function for India news
def india():
print(fg('cyan') + "\n << Here is Today's India News >>" + reset)
speak("Here is Today's news of India")
url="http://newsapi.org/v2/top-headlines?country=in&apiKey=3e33ba1948eb4504b47af11904512730"
news=requests.get(url).text # creating url request
news_dict=json.loads(news) # creating python object
contents=news_dict["articles"]
i=1
print('\n--------------------------------------------------------------------------------------------')
for content in contents: # iterating the news
print(fg('yellow') + '(',i,')',content['title'],'\n' + reset)
speak(str(i))
speak(content['title'])
if(content['description']):
print(fg('cyan')+'->',content['description']+reset)
speak(content['description'])
i=i+1
print('\n----------------------------------------------------------------------------------------------')
print(fg('cyan') + '\n********** Thank you for listening..... ***********' + reset)
speak("thank you for listening")
# function for health news
def health():
print(fg('cyan')+"\n << Here is Today's Health News >>"+reset)
speak("Here is Today's health news")
url="http://newsapi.org/v2/top-headlines?country=in&category=health&apiKey=3e33ba1948eb4504b47af11904512730"
news=requests.get(url).text # creating url request
news_dict=json.loads(news) # creating python object
contents=news_dict["articles"]
i=1
print('\n--------------------------------------------------------------------------------------------')
for content in contents: # iterating the news
print(fg(3)+'(',i,')',content['title'],'\n'+reset)
speak(str(i))
speak(content['title'])
if(content['description']):
print(fg('cyan')+'->',content['description']+reset)
speak(content['description'])
i=i+1
print('\n----------------------------------------------------------------------------------------------')
print(fg('cyan') + '\n********** Thank you for listening..... ***********' + reset)
speak("thank you for listening")
# function for Technology news
def technology():
print(fg('cyan')+"\n << Here is Today's Technology News >>"+reset)
speak("Here is Today's Technology news")
url="http://newsapi.org/v2/top-headlines?country=in&category=technology&apiKey=3e33ba1948eb4504b47af11904512730"
news=requests.get(url).text # creating url request
news_dict=json.loads(news) # creating python object
contents=news_dict["articles"]
i=1
print('\n--------------------------------------------------------------------------------------------')
for content in contents: # iterating the news
print(fg(3)+'(',i,')',content['title'],'\n'+reset)
speak(str(i))
speak(content['title'])
if(content['description']):
print(fg('cyan')+'->',content['description']+reset)
speak(content['description'])
i=i+1
print('\n----------------------------------------------------------------------------------------------')
print(fg('cyan')+'\n********** Thank you for listening..... ***********'+reset)
speak("thank you for listening")
# function for Science news
def science():
print(fg('cyan')+"\n << Here is Today's Science News >>"+reset)
speak("Here is Today's Science news")
url="http://newsapi.org/v2/top-headlines?country=in&category=science&apiKey=3e33ba1948eb4504b47af11904512730"
news=requests.get(url).text # creating url request
news_dict=json.loads(news) # creating python object
contents=news_dict["articles"]
i=1
print('\n--------------------------------------------------------------------------------------------')
for content in contents: # iterating the news
print(fg(3)+'(',i,')',content['title'],'\n'+reset)
speak(str(i))
speak(content['title'])
if(content['description']):
print(fg('cyan')+'->',content['description']+reset)
speak(content['description'])
i=i+1
print('\n----------------------------------------------------------------------------------------------')
print(fg('cyan')+'\n********** Thank you for listening..... ***********'+reset)
speak("thank you for listening")
# function for entertainment news
def entertainment():
print(fg('cyan') + "\n << Here is Today's Entertainment News >>" + reset)
speak("Here is Today's entertainment news")
url="http://newsapi.org/v2/top-headlines?country=in&category=entertainment&apiKey=3e33ba1948eb4504b47af11904512730"
news=requests.get(url).text # creating url request
news_dict=json.loads(news) # creating python object
contents=news_dict["articles"]
i=1
print('\n--------------------------------------------------------------------------------------------')
for content in contents: # iterating the news
print(fg(3)+'(',i,')',content['title'],'\n'+reset)
speak(str(i))
speak(content['title'])
if(content['description']):
print(fg('cyan')+'->',content['description']+reset)
speak(content['description'])
i=i+1
print('\n----------------------------------------------------------------------------------------------')
print(fg('cyan')+'\n********** Thank you for listening..... ***********'+reset)
speak("thank you for listening")
# function for sports news
def sports():
print(fg('cyan') + "\n << Here is Today's Sports News >>" + reset)
speak("Here is Today's sports news")
url="http://newsapi.org/v2/top-headlines?country=in&category=sports&apiKey=3e33ba1948eb4504b47af11904512730"
news=requests.get(url).text # creating url request
news_dict=json.loads(news) # creating python object
contents=news_dict["articles"]
i=1
print('\n--------------------------------------------------------------------------------------------')
for content in contents: # iterating the news
print(fg(3)+'(',i,')',content['title'],'\n'+reset)
speak(str(i))
speak(content['title'])
if(content['description']):
print(fg('cyan')+'->',content['description']+reset)
speak(content['description'])
i=i+1
print('\n----------------------------------------------------------------------------------------------')
print(fg('cyan')+'\n********** Thank you for listening..... ***********'+reset)
speak("thank you for listening")
def business():
print(fg('cyan') + "\n << Here is Today's Business News >>" + reset)
speak("Here is Today's business news")
url="http://newsapi.org/v2/top-headlines?country=in&category=business&apiKey=3e33ba1948eb4504b47af11904512730"
news=requests.get(url).text # creating url request
news_dict=json.loads(news) # creating python object
contents=news_dict["articles"]
i=1
print('\n--------------------------------------------------------------------------------------------')
for content in contents: # iterating the news
print(fg(3)+'(',i,')',content['title'],'\n',reset)
speak(str(i))
speak(content['title'])
if(content['description']):
print(fg('cyan')+'->',content['description']+reset)
speak(content['description'])
i=i+1
print('\n----------------------------------------------------------------------------------------------')
print(fg('cyan')+'\n********** Thank you for listening..... ***********'+reset)
speak("thank you for listening")