<commit_before>from six.moves import input

from plugin import plugin, require
from colorama import Fore
from pycricbuzz import Cricbuzz


@require(network=True)
@plugin('cricket')
class Cricket():
    """
    Enter cricket and follow the instructions
    """
    def __init__(self):
        self.c = Cricbuzz()

    def __call__(self, jarvis, s):
        self._refresh()
        self.score(jarvis)

    def _refresh(self):
        self.all_match_data = self.c.matches()
        self.matches = []
        d = {}
        for match in self.all_match_data:
            d['id'] = match['id']
            d['srs'] = match['srs']
            d['mnum'] = match['mnum']
            self.matches.append(d.copy())

    def live_score(self, index):
        if self.all_match_data[index]['mchstate'] == 'preview':
            return(Fore.RED + "MATCH YET TO BEGIN")
        selected_match = self.all_match_data[index]
        data = self.c.livescore(self.matches[index]['id'])
        score = {}
        score['matchinfo'] = "{}, {}".format(selected_match['srs'], selected_match['mnum'])
        score['status'] = "{}".format(selected_match['status'])
        score['bowling'] = data['bowling']
        score['batting'] = data['batting']

        text = ''
        text += Fore.LIGHTYELLOW_EX + score['matchinfo'] + '\n' + score['status'] + '\n\n'

        text += Fore.BLUE + score['batting']['team'] + Fore.BLACK
        for scr in reversed(score['batting']['score']):
            text += " :- {}/{} in {} overs\n".format(scr['runs'], scr['wickets'], scr['overs'])
        for b in reversed(score['batting']['batsman']):
            text += "{} : {}({}) \n".format(b['name'].strip('*'), b['runs'], b['balls'])

        text += Fore.BLUE + '\n' + score['bowling']['team'] + Fore.BLACK
        for scr in reversed(score['bowling']['score']):
            text += " :- {}/{} in {} overs\n".format(scr['runs'], scr['wickets'], scr['overs'])
        for b in reversed(score['bowling']['bowler']):
            text += "{} : {}/{} \n".format(b['name'].strip('*'), b['wickets'], b['runs'])
        text += Fore.RESET

        return text

    def commentary(self, index):
        selected_match = self.all_match_data[index]
        data = self.c.commentary(self.matches[index]['id'])
        comm = {}
        comm['matchinfo'] = "{}, {}".format(selected_match['srs'], selected_match['mnum'])
        comm['status'] = "{}".format(selected_match['status'])
        comm['commentary'] = data['commentary']
        text = []
        for com in comm['commentary']:
            line = ''
            if com['over']:
                line += com['over'] + ' : '
            line += "{}\n\n".format(com['comm'])
            # doing bold breaklines and italics looks good in terminal
            text.append(line.replace('<b>', '\033[1m').replace('</b>', '\033[0m')
                            .replace('<br/>', '\n').replace('<i>', '\x1B[3m').replace('</i>', '\x1B[23m'))

        text.reverse()

        commentary = Fore.LIGHTYELLOW_EX + comm['matchinfo'] + '\n' + comm['status'] + '\n\n' + Fore.RESET
        for line in text:
            commentary += line

        return commentary

    def scorecard(self, index):
        selected_match = self.all_match_data[index]
        data = self.c.scorecard(self.matches[index]['id'])
        card = {}
        card['matchinfo'] = "{}, {}".format(selected_match['srs'], selected_match['mnum'])
        card['status'] = "{}".format(selected_match['status'])
        card['scorecard'] = data['scorecard']
        text = ''
        text += Fore.LIGHTYELLOW_EX + card['matchinfo'] + '\n' + card['status'] + '\n\n'
        text += Fore.BLACK + '*' * 35 + '\n\n'

        for scr in reversed(card['scorecard']):
            text += Fore.LIGHTYELLOW_EX + "{}\nInnings: {}\n{}/{} in {} overs\n\n".format(scr['batteam'], scr['inng_num'],
                                                                                          scr['runs'], scr['wickets'], scr['overs'])
            text += Fore.BLUE + "Batting\n"
            text += Fore.RED + "{:<17} {:<3} {:<3} {:<3} {}\n\n".format('Name', 'R', 'B', '4', '6')
            for b in scr['batcard']:
                text += Fore.BLACK + "{:<17} {:<3} {:<3} {:<3} {}\n{}\n\n".format(b['name'], b['runs'], b['balls'],
                                                                                  b['fours'], b['six'], b['dismissal'])
            text += Fore.LIGHTYELLOW_EX + "-" * 35 + "\n\n"
            text += Fore.BLUE + "Bowling\n"
            text += Fore.RED + "{:<17} {:<5} {:<3} {:<3} {}\n\n".format('Name', 'O', 'M', 'R', 'W')
            for b in scr['bowlcard']:
                text += Fore.BLACK + "{:<17} {:<5} {:<3} {:<3} {}\n\n".format(b['name'], b['overs'], b['maidens'],
                                                                              b['runs'], b['wickets'])
            text += Fore.BLUE + '*' * 35 + '\n\n'
        return text

    def score(self, jarvis):
        print(Fore.RED + "\nALL MATCHES\n" + Fore.LIGHTBLUE_EX)
        if self.matches == []:
            print("No Matches Being Played!\n", Fore.RED)
            return
        for i, m in enumerate(self.matches, 1):
            print("{}. {} {}".format(str(i), m['srs'], m['mnum']))
        choice = int(input(Fore.RED + '\nEnter choice (number): ' + Fore.RESET))
        while choice < 1 or choice > len(self.matches):
            print(Fore.BLACK + '\nWrong choice')
            choice = int(input(Fore.RED + '\nEnter choice again: ' + Fore.RESET))

        selected_match_id = choice - 1
        print('')
        res = self.live_score(selected_match_id)
        print(res)

        if(res == Fore.RED + "MATCH YET TO BEGIN"):
            return

        while True:
            print(Fore.LIGHTBLUE_EX + '1. Full Score Card')
            print('2. Commentary')
            print('3. Refresh Score')
            print('4. Quit' + Fore.RESET)

            choice = int(input(Fore.RED + '\nEnter choice (number): ' + Fore.RESET))
            while choice < 1 or choice > 4:
                print(Fore.BLACK + '\nWrong choice')
                choice = int(input(Fore.RED + '\nEnter choice again: ' + Fore.RESET))
            print('')

            if choice == 1:
                print(self.scorecard(selected_match_id))
                ref = input(Fore.RED + 'Do you want to refresh:(y/n) ' + Fore.RESET)
                while ref == 'y':
                    print(self.scorecard(selected_match_id))
                    ref = input(Fore.RED + 'Do you want to refresh:(y/n) ' + Fore.RESET)

            elif choice == 2:
                print(self.commentary(selected_match_id))
                ref = input(Fore.RED + 'Do you want to refresh:(y/n) ' + Fore.RESET)
                while ref == 'y':
                    print(self.commentary(selected_match_id))
                    ref = input(Fore.RED + 'Do you want to refresh:(y/n) ' + Fore.RESET)

            elif choice == 3:
                ref = 'y'
                while ref == 'y':
                    print(self.live_score(selected_match_id))<commit_msg>fix ErrorValue in 'score' function of cricket plugin<commit_after>from six.moves import input

from plugin import plugin, require
from colorama import Fore
from pycricbuzz import Cricbuzz


@require(network=True)
@plugin('cricket')
class Cricket():
    """
    Enter cricket and follow the instructions
    """
    def __init__(self):
        self.c = Cricbuzz()

    def __call__(self, jarvis, s):
        self._refresh()
        self.score(jarvis)

    def _refresh(self):
        self.all_match_data = self.c.matches()
        self.matches = []
        d = {}
        for match in self.all_match_data:
            d['id'] = match['id']
            d['srs'] = match['srs']
            d['mnum'] = match['mnum']
            self.matches.append(d.copy())

    def live_score(self, index):
        if self.all_match_data[index]['mchstate'] == 'preview':
            return(Fore.RED + "MATCH YET TO BEGIN")
        selected_match = self.all_match_data[index]
        data = self.c.livescore(self.matches[index]['id'])
        score = {}
        score['matchinfo'] = "{}, {}".format(selected_match['srs'], selected_match['mnum'])
        score['status'] = "{}".format(selected_match['status'])
        score['bowling'] = data['bowling']
        score['batting'] = data['batting']

        text = ''
        text += Fore.LIGHTYELLOW_EX + score['matchinfo'] + '\n' + score['status'] + '\n\n'

        text += Fore.BLUE + score['batting']['team'] + Fore.BLACK
        for scr in reversed(score['batting']['score']):
            text += " :- {}/{} in {} overs\n".format(scr['runs'], scr['wickets'], scr['overs'])
        for b in reversed(score['batting']['batsman']):
            text += "{} : {}({}) \n".format(b['name'].strip('*'), b['runs'], b['balls'])

        text += Fore.BLUE + '\n' + score['bowling']['team'] + Fore.BLACK
        for scr in reversed(score['bowling']['score']):
            text += " :- {}/{} in {} overs\n".format(scr['runs'], scr['wickets'], scr['overs'])
        for b in reversed(score['bowling']['bowler']):
            text += "{} : {}/{} \n".format(b['name'].strip('*'), b['wickets'], b['runs'])
        text += Fore.RESET

        return text

    def commentary(self, index):
        selected_match = self.all_match_data[index]
        data = self.c.commentary(self.matches[index]['id'])
        comm = {}
        comm['matchinfo'] = "{}, {}".format(selected_match['srs'], selected_match['mnum'])
        comm['status'] = "{}".format(selected_match['status'])
        comm['commentary'] = data['commentary']
        text = []
        for com in comm['commentary']:
            line = ''
            if com['over']:
                line += com['over'] + ' : '
            line += "{}\n\n".format(com['comm'])
            # doing bold breaklines and italics looks good in terminal
            text.append(line.replace('<b>', '\033[1m').replace('</b>', '\033[0m')
                            .replace('<br/>', '\n').replace('<i>', '\x1B[3m').replace('</i>', '\x1B[23m'))

        text.reverse()

        commentary = Fore.LIGHTYELLOW_EX + comm['matchinfo'] + '\n' + comm['status'] + '\n\n' + Fore.RESET
        for line in text:
            commentary += line

        return commentary

    def scorecard(self, index):
        selected_match = self.all_match_data[index]
        data = self.c.scorecard(self.matches[index]['id'])
        card = {}
        card['matchinfo'] = "{}, {}".format(selected_match['srs'], selected_match['mnum'])
        card['status'] = "{}".format(selected_match['status'])
        card['scorecard'] = data['scorecard']
        text = ''
        text += Fore.LIGHTYELLOW_EX + card['matchinfo'] + '\n' + card['status'] + '\n\n'
        text += Fore.BLACK + '*' * 35 + '\n\n'

        for scr in reversed(card['scorecard']):
            text += Fore.LIGHTYELLOW_EX + "{}\nInnings: {}\n{}/{} in {} overs\n\n".format(scr['batteam'], scr['inng_num'],
                                                                                          scr['runs'], scr['wickets'], scr['overs'])
            text += Fore.BLUE + "Batting\n"
            text += Fore.RED + "{:<17} {:<3} {:<3} {:<3} {}\n\n".format('Name', 'R', 'B', '4', '6')
            for b in scr['batcard']:
                text += Fore.BLACK + "{:<17} {:<3} {:<3} {:<3} {}\n{}\n\n".format(b['name'], b['runs'], b['balls'],
                                                                                  b['fours'], b['six'], b['dismissal'])
            text += Fore.LIGHTYELLOW_EX + "-" * 35 + "\n\n"
            text += Fore.BLUE + "Bowling\n"
            text += Fore.RED + "{:<17} {:<5} {:<3} {:<3} {}\n\n".format('Name', 'O', 'M', 'R', 'W')
            for b in scr['bowlcard']:
                text += Fore.BLACK + "{:<17} {:<5} {:<3} {:<3} {}\n\n".format(b['name'], b['overs'], b['maidens'],
                                                                              b['runs'], b['wickets'])
            text += Fore.BLUE + '*' * 35 + '\n\n'
        return text

    def score(self, jarvis):
        print(Fore.RED + "\nALL MATCHES\n" + Fore.LIGHTBLUE_EX)
        if self.matches == []:
            print("No Matches Being Played!\n", Fore.RED)
            return
        for i, m in enumerate(self.matches, 1):
            print("{}. {} {}".format(str(i), m['srs'], m['mnum']))
        while 1:
            try:
                choice = int(input(Fore.RED + '\nEnter choice (number): ' + Fore.RESET))
                while choice < 1 or choice > len(self.matches):
                    print(Fore.BLACK + '\nWrong choice')
                    choice = int(input(Fore.RED + '\nEnter choice again: ' + Fore.RESET))
                break
            except ValueError:
                print("Invalid type of choice. Please enter an integer number")

        selected_match_id = choice - 1
        print('')
        res = self.live_score(selected_match_id)
        print(res)

        if(res == Fore.RED + "MATCH YET TO BEGIN"):
            return

        while True:
            print(Fore.LIGHTBLUE_EX + '1. Full Score Card')
            print('2. Commentary')
            print('3. Refresh Score')
            print('4. Quit' + Fore.RESET)

            while 1:
                try:
                    choice = int(input(Fore.RED + '\nEnter choice (number): ' + Fore.RESET))
                    while choice < 1 or choice > 4:
                        print(Fore.BLACK + '\nWrong choice')
                        choice = int(input(Fore.RED + '\nEnter choice again: ' + Fore.RESET))
                    break
                except ValueError:
                    print("Invalid type of choice. Please enter an integer number")
            print('')

            if choice == 1:
                print(self.scorecard(selected_match_id))
                ref = input(Fore.RED + 'Do you want to refresh:(y/n) ' + Fore.RESET)
                while ref == 'y':
                    print(self.scorecard(selected_match_id))
                    ref = input(Fore.RED + 'Do you want to refresh:(y/n) ' + Fore.RESET)

            elif choice == 2:
                print(self.commentary(selected_match_id))
                ref = input(Fore.RED + 'Do you want to refresh:(y/n) ' + Fore.RESET)
                while ref == 'y':
                    print(self.commentary(selected_match_id))
                    ref = input(Fore.RED + 'Do you want to refresh:(y/n) ' + Fore.RESET)

            elif choice == 3:
                ref = 'y'
                while ref == 'y':
                    print(self.live_score(selected_match_id))
{'fraction_non_alphanumeric': 0.18575046198069947, 'fraction_numerical': 0.007391691191567996, 'mean_word_length': 1.8763779527559055, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4795623', 'n_tokens_mistral': 4603, 'n_tokens_neox': 4386, 'n_words': 946}