
I wrote a simple python script that I thought of sharing here. The code fetches the latest cricket score of the live matches and send you a notification using libnotify on the desktop every second. Here is the code.
#!/usr/bin/env python
import requests
from bs4 import BeautifulSoup
import pynotify
from time import sleep
def sendmessage(title, message):
pynotify.init("Test")
notice = pynotify.Notification(title, message)
notice.show()
return
url = "
http://static.cricinfo.com/rss/livescores.xml"
while True:
r = requests.get(url)
while r.status_code is not 200:
r = requests.get(url)
soup = BeautifulSoup(r.text)
data = soup.find_all("description")
score = data[3].text
sendmessage("Score", score)
sleep(60)
There is some hard coding on line 18, I set the index to the match I am interested in, in case there are many cricket matches happening at the same time.
This is not perfect, I did it just for fun. Would love to hear your thoughts on it.