This repository has been archived by the owner on Aug 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from asdofindia/master
Added ability to choose match, selective notifications
- Loading branch information
Showing
2 changed files
with
56 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |