-
Notifications
You must be signed in to change notification settings - Fork 8
/
news.py
83 lines (64 loc) · 2.23 KB
/
news.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
from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
import time
from espeak import espeak
import sys
url = "http://www.timesofindia.indiatimes.com"
response =urlopen(url)
html = response.read()
pattern = re.compile('new_tops#[0-9]{1,}')
soup = BeautifulSoup(html,"html.parser")
data = soup.findAll('a',{"pg":pattern})
i=0
for a in data:
print (a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
i+=1
if(i%2==0):
espeak.synth (a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
time.sleep(3)
print("===============================================================")
print("=======================================================================")
print('')
print("=======================================================================")
pattern2 = re.compile('new_latest#[0-9]{1,2}')
data2 = soup.findAll('a',{"pg":pattern2})
i=0
for a in data2:
print(a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
i+=1
if(i%3==0):
espeak.synth(a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
time.sleep(3)
print("===============================================================")
pattern_world = re.compile('World#[0-9]{1,2}')
data3= soup.findAll('a',{"pg":pattern_world})
i=0
for a in data3:
print(a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
i+=1
if(i%2==0):
espeak.synth(a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
time.sleep(3)
print("===============================================================")
pattern_science = re.compile('Science#[0-9]{1,2}')
data4= soup.findAll('a',{"pg":pattern_science})
i=0
for a in data4:
print(a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
i+=1
if(i%2==0):
espeak.synth(a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
time.sleep(3)
print("===============================================================")
pattern_education = re.compile('Education#[0-9]{1,2}')
data5= soup.findAll('a',{"pg":pattern_education})
i=0
for a in data5:
print(a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
i+=1
if(i%3==0):
espeak.synth(a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
time.sleep(3)
print("===============================================================")
time.sleep(3)