Skip to content
This repository has been archived by the owner on Aug 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from asdofindia/master
Browse files Browse the repository at this point in the history
Added ability to choose match, selective notifications
  • Loading branch information
Anubhav Yadav committed Mar 25, 2015
2 parents 45b92f8 + bda90bb commit dc1f882
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# scorer.py
A simple python script to fetch cricket scores and send notifications.

## Features ##
* Allows you to choose from concurrent matches
* Change choice by Ctrl+C
* Quit by Ctrl+C twice
* Shows notification only if there's a change in the score (run or wicket)

## Requirements ##
* libnotify, BeautifulSoup
* Internet connection

## Credits ##
* [CricInfo](http://www.espncricinfo.com/) for providing score
* [Anubhav Yadav](http://www.quora.com/What-are-some-cool-Python-tricks/answer/Anubhav-Yadav-5) for initial code and idea
* [Akshay S Dinesh](https://github.com/asdofindia)
51 changes: 41 additions & 10 deletions scorer.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,51 @@
#!/usr/bin/env python2
#!/usr/bin/env python3

import requests
from bs4 import BeautifulSoup
import pynotify
from gi.repository import Notify
from time import sleep


def sendmessage(title, message):
pynotify.init("Test")
notice = pynotify.Notification(title, message)
notice.show()
return
Notify.init("Scorer")
scorer = Notify.Notification.new(title, message, "dialog-information")
scorer.show()
return


url = "http://static.cricinfo.com/rss/livescores.xml"
match = 0
score = ""
interrupted=False

print("Fetching matches..")
while True:
try:
r = requests.get(url)
while r.status_code is not 200:
r = requests.get(url)
sleep(2)
r = requests.get(url)
soup = BeautifulSoup(r.text)
data = soup.find_all("description")
score = data[2].text
sendmessage("Score", score)
sleep(60)
if match == 0:
print("Matches available:")
counter = 1
for game in data[1:]:
print(counter, game.text)
counter += 1
match = int(input("Enter your choice: "))
interrupted=False
newscore = data[match].text
if newscore != score:
score = newscore
sendmessage("Score", score)
sleep(15)

except KeyboardInterrupt:
if interrupted:
print("Bye bye")
break
else:
print("Press Ctrl+C again to quit")
match = 0
interrupted=True

0 comments on commit dc1f882

Please sign in to comment.