Ejemplo n.º 1
0
def popUpMessage(title, message):
    logger.info("Initializing pynotify")
    try:
        pynotify.init("Scorer")
        pynotify.Notification(title, message, "dialog-information").show()
    except Exception as e:
        logger.error("Error initializing pynotify")
        logger.debug(e)
        logger.info("Unable to initialize pynotify: Connection Refused")
        logger.info("Quitting the app")
        exitApp()
Ejemplo n.º 2
0
def popUpMessage(title, message):
    logger.info("Initializing pynotify")
    try:
        pynotify.init("Scorer")
        pynotify.Notification(title, message, "dialog-information").show()
    except Exception as e:
        logger.error("Error initializing pynotify")
        logger.debug(e)
        logger.info("Unable to initialize pynotify: Connection Refused")
        logger.info("Quitting the app")
        exitApp()
Ejemplo n.º 3
0
def getLastestScore(jsonurl, playingTeams):
    logger.info("Entry Point for getLastestScore")
    logger.debug("Url to get the latest json is: {}".format(jsonurl))
    try:
        r = requests.get(jsonurl)
    except:
        logger.error("not able to reach the site to get the match info!!")
        exitApp()

    jsonData = r.json()
    matchStatus = jsonData.get("live").get("status")
    logger.info("matchStatus: {}".format(matchStatus))
    titleToDisplay = matchStatus
    scoreToDisplay = ""
    # Check if match Started
    if (not jsonData.get("live").get("innings")):
        logger.info("Match not started")
        return (titleToDisplay, scoreToDisplay)

    # Check if match over
    if (WON_STATUS in matchStatus):
        logger.info("Match over")
        return (titleToDisplay, scoreToDisplay)
    innings = jsonData.get("live").get("innings")
    batting_team_id = innings.get("batting_team_id")
    battingTeamName = playingTeams[batting_team_id]
    bowling_team_id = innings.get("bowling_team_id")
    bowlingTeamName = playingTeams.get(bowling_team_id)
    overs = innings.get("overs")
    logger.debug("Found Overs: {}".format(overs))
    runs = innings.get("runs")
    logger.debug("Found Runs: {}".format(runs))
    wickets = innings.get("wickets")
    logger.debug("Found wickets: {}".format(wickets))
    try:
        requiredRuns = jsonData.get("comms")[1].get("required_string")
    except IndexError:
        requiredRuns = ""
    logger.debug("The requiredRuns string is: {}".format(requiredRuns))
    titleToDisplay = battingTeamName + " vs " + bowlingTeamName
    scoreToDisplay = "score: " + runs + "/" + wickets + "\n\
    " + "overs: " + overs + "\n" + requiredRuns
    logger.debug("The display string is: {} {} \
        ".format(titleToDisplay, scoreToDisplay))
    return (titleToDisplay, scoreToDisplay)
Ejemplo n.º 4
0
def getPlayingTeamNames(jsonurl):
    """
    Get the names of the teams playing the matches.
    :param jsonurl: url for the json.
    :type jsonurl: `str`
    :return: teams playing
    """
    logger.info("Url to get the json from {}".format(jsonurl))
    try:
        r = requests.get(jsonurl)
    except:
        logger.error("not able to reach the site to get the match info!!")
        exitApp()

    jsonData = r.json()
    playingTeams = {
        team.get("team_id"): team.get("team_name")
        for team in jsonData.get("team")
    }
    logger.debug("playingTeams: {}".format(playingTeams))
    return playingTeams
Ejemplo n.º 5
0
def findMatchesAvailable(url="http://static.cricinfo.com/rss/livescores.xml"):
    """
    Find all the matches available for the day.
    :param url: url for the matches for the day.
    :param url: `str`
    :return: a tuple of xml and matches.
    """
    logger.info("Entry point for findMatchesAvailable")
    try:
        r = requests.get(url)
    except:
        logger.error("not able to reach the site to get the match info!!")
        exitApp()

    soup = BeautifulSoup(r.text)
    xml = soup.find_all("item")
    matches = map(
        lambda item: re.sub(
            r'\s+', " ", re.sub('\
        [^A-Za-z ]+', '', item.title.text)), xml)
    return (xml, matches)
Ejemplo n.º 6
0
def main():
    while True:
        logger.debug("Getting the xml and matches list")
        xml, matches = fs.findMatchesAvailable()
        if(matches[0]==NO_LIVE_MATCHES):
            print "No Live matches are available now:"
            exitApp()
        matches.append("Quit the scorer app")
        try:
            matchChoice= getUserInput(matches)
        except KeyboardInterrupt:
            exitApp()
        if(matchChoice == len(matches) -1 ):
            logger.debug("User chose quit")
            exitApp()
        logger.debug("User's choice: {} {}".format(matchChoice, matches[matchChoice-1]))
        logger.debug("Getting the latest score for the selected match")
        matchID = fs.getMatchID(matchChoice,xml)
        jsonurl = fs.getJsonURL(matchID)
        playingTeams = fs.getPlayingTeamNames(jsonurl)
        while True:
            try:
                title,score = fs.getLastestScore(jsonurl,playingTeams)
                logger.debug("Sending notification for: title:{} score:{}".format(title, score))
                notify.popUpMessage(title, score)
                sleep(SLEEP_INTERVAL)
            except KeyboardInterrupt:
                break
Ejemplo n.º 7
0
def main():
    while True:
        logger.debug("Getting the xml and matches list")
        xml, matches = fs.findMatchesAvailable()
        if (matches[0] == NO_LIVE_MATCHES):
            print "No Live matches are available now:"
            exitApp()
        matches.append("Quit the scorer app")
        try:
            matchChoice = getUserInput(matches)
        except KeyboardInterrupt:
            exitApp()
        if (matchChoice == len(matches) - 1):
            logger.debug("User chose quit")
            exitApp()
        logger.debug("User's choice: {} {}".format(matchChoice,
                                                   matches[matchChoice - 1]))
        logger.debug("Getting the latest score for the selected match")
        matchID = fs.getMatchID(matchChoice, xml)
        jsonurl = fs.getJsonURL(matchID)
        playingTeams = fs.getPlayingTeamNames(jsonurl)
        while True:
            try:
                title, score = fs.getLastestScore(jsonurl, playingTeams)
                logger.debug("Sending notification for: title:{} score:\
                    {}".format(title, score))
                notify.popUpMessage(title, score)
                sleep(SLEEP_INTERVAL)
            except KeyboardInterrupt:
                break