-
Notifications
You must be signed in to change notification settings - Fork 109
/
news2.py
executable file
·34 lines (32 loc) · 1.02 KB
/
news2.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import datetime
from bs4 import BeautifulSoup
import random
from time import sleep
import pynotify
while True:
try:
li = ['india-news','world-news','sports','movies']
k = random.randint(0,3)
sc = requests.get('http://www.abplive.in/'+li[k])
soup = BeautifulSoup(sc.text,'lxml')
head = soup.select('h1 > a')
basic = soup.select('h5 > a')
news = head + basic
while True:
i = random.randrange(0,len(news)-1)
j = random.randrange(0,len(news)-1)
if i == j:
continue
else:
pynotify.init('test')
n = pynotify.Notification('Live News','* '+news[i].text+'\n'+'* '+news[j].text)
n.show()
break
except requests.exceptions.ConnectionError:
pynotify.init('test')
n = pynotify.Notification('Connection Issue','No internet found')
n.show()
sleep(90)