Skip to content

Commit

Permalink
Merge pull request anubhavcodes#13 from srivallabh/master
Browse files Browse the repository at this point in the history
Making a few coding style enhancements.
  • Loading branch information
Anubhav Yadav committed Mar 26, 2015
2 parents 9b3c161 + 180d2fe commit 34bfd7e
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

logging.basicConfig(level=logging.DEBUG)

def sendmessage(title, message):
def popUpMessage(title, message):
if notifyModule is "pynotify":
logging.debug("Initializing pynotify")
pynotify.init("Scorer")
Expand All @@ -34,41 +34,47 @@ def sendmessage(title, message):
notify2.Notification(title, message, "dialog-information").show()


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

liveUrl = "http://static.cricinfo.com/rss/livescores.xml"
matchChoice = 0
score = ""
didInterrupt = False


print("Fetching matches..")
while True:
try:
logging.info("Sending requests")
r = requests.get(url)
while r.status_code is not 200:
dataFromUrl = requests.get(liveUrl)
while dataFromUrl.status_code is not 200:
logging.debug("Request failed: trying again")
sleep(2)
r = requests.get(url)
data = BeautifulSoup(r.text).find_all("description")
if not match:
dataFromUrl = requests.get(liveUrl)
data = BeautifulSoup(dataFromUrl.text).find_all("description")
if not matchChoice:
print("Matches available:")
for counter, game in enumerate(data[1:], 1):
print(counter, str(game.text))
match = int(input("Enter your choice: "))
for index, game in enumerate(data[1:], 1):
print(index, str(game.text))
matchChoice = int(input("Enter your choice: "))
while True:
if match in range(1, counter):
if matchChoice in range(1, index):
break
match = int(input("Invalid Choice. Enter your choice: "))
interrupted=False
newscore = data[match].text
matchChoice = int(input("Invalid Choice. Enter your choice: "))
didInterrupt=False
newscore = data[matchChoice].text
logging.info("Score found is {}".format(newscore))
if newscore != score:
logging.info("This is the most recent score, send me a notification")
score = newscore
sendmessage("Score", score)
popUpMessage("Score", score)
sleep(15)

except KeyboardInterrupt:
if interrupted:
if didInterrupt:
logging.info("keyboard interrupted, once")
print("Bye bye")
break
else:
print("Press Ctrl+C again to quit")
match, interrupted = 0, True
matchChoice, didInterrupt = 0, True

0 comments on commit 34bfd7e

Please sign in to comment.