-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinshorts.py
More file actions
51 lines (41 loc) · 1.43 KB
/
inshorts.py
File metadata and controls
51 lines (41 loc) · 1.43 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
from bs4 import BeautifulSoup
import requests
import html5lib
import pyttsx3
import time
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice',voices[1].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
URL = "https://inshorts.com/en/read"
response = requests.get(URL)
soup = BeautifulSoup(response.content, 'html5lib')
headlines = soup.findAll('span', attrs = {'itemprop' : 'headline'})
count_headlines = len(headlines)
speak("Welcome to audioShorts where you will get the Headlines of the inshorts news")
speak("Do you want subtitles for news?")
print("1 for Yes and 0 for No")
check = int(input())
if check != 0 and check != 1:
speak("I do not understand your choice sir")
exit()
speak("There are " + str(count_headlines) + 'headlines for today')
speak("How many do you want to listen?")
listen_count = int(input("No. of headlines?"))
if listen_count <= count_headlines and check is 1 or check is 0:
for i in range(listen_count):
speak('News number ' + str(i + 1))
time.sleep(0.4)
if check == 1:
print("**** NEWS NUMBER " + str(i+1) + " ****")
print(headlines[i].text)
print("")
speak(headlines[i].text)
time.sleep(1)
elif check == 0:
speak(headlines[i].text)
time.sleep(1)
else:
speak("You are a dumbass")