diff --git a/scorer.py b/scorer.py index 07f8137..1be9ac3 100755 --- a/scorer.py +++ b/scorer.py @@ -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") @@ -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 +