A simple python script to fetch latest cricket scores and send a notification using libnotify

2,072 views
Skip to first unread message

Anubhav Yadav

unread,
Mar 24, 2015, 7:37:59 AM3/24/15
to pytho...@googlegroups.com





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.

Mandar Vaze / मंदार वझे

unread,
Mar 24, 2015, 1:12:20 PM3/24/15
to pythonpune
This is not perfect, I did it just for fun. Would love to hear your thoughts on it.

You can put this on github, and share link here/twitter/FB/G+ (anywhere really).

Benefits :
  • You can keep updating/improving it (You said yourself it is not perfect, so I assume you want to make it better)
  • Others can comment, fork
  • It is a good showcase of your skills for your prospective employers (But not everybody may care about this)
Best Wishes !!

-Mandar

Anubhav Yadav

unread,
Mar 25, 2015, 11:17:26 AM3/25/15
to pytho...@googlegroups.com

You can put this on github, and share link here/twitter/FB/G+ (anywhere really).



Hi,
Thanks for commenting. It's on github here:  https://github.com/neo1691/scorer.py/tree/develop
It has already evolved in one day. Would love to see you or other pythonist here improve it further. Thanks alot again.

Mandar Vaze / मंदार वझे

unread,
Mar 25, 2015, 1:09:11 PM3/25/15
to pythonpune
Seems like Quora has been kind to you (I too upvoted the script there)

-Mandar
Reply all
Reply to author
Forward
0 new messages