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

Added ability to choose match, selective notifications #1

Merged
merged 4 commits into from
Mar 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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