fluxion

Times Of India Headlines Desktop Notifications.

Jun 27th, 2016
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3. import subprocess
  4. import time
  5.  
  6. url = "http://timesofindia.indiatimes.com/"
  7.  
  8. def open_url(url):
  9.     return requests.get(url).text  # returns html
  10.  
  11. def get_bsoup_object(html):
  12.     return BeautifulSoup(html, "lxml")  # returns soup (BeautifulSoup's object)
  13.  
  14.  
  15. def sendmessage(message):
  16.     subprocess.Popen(['notify-send', message])
  17.     return
  18.  
  19.  
  20. def main():
  21.     myhtml = open_url(url)
  22.     soup = get_bsoup_object(myhtml)
  23.     j = 1
  24.    
  25.     for i in soup.find('ul',attrs={'class':'list9'}).findAll('li'):
  26.         #print(str(j) + " " + i.text)
  27.         sendmessage(str(j) + " " + i.text)
  28.         time.sleep(10)
  29.         j += 1
  30.        
  31.  
  32.  
  33. while True:
  34.     main()
  35.     time.sleep(3600)
Add Comment
Please, Sign In to add comment