async def score_card(ctx): c = Cricbuzz() try: scorecard = c.scorecard(match_id())['scorecard'][0] except: await ctx.send('abe saale abhi to koi game nahi chal raha hai') return embed1 = discord.Embed(title=f"Batting Team : {scorecard['batteam']}", colour=discord.Colour.blue()) embed1.description = f"Score {scorecard['runs']}/{scorecard['wickets']}, Overs {scorecard['overs']}" for I in scorecard['batcard']: embed1.add_field(name=I['name'], value=f"Runs{I['runs']}\n" f"Balls Faced {I['balls']}\n" f"Fours {I['fours']}\n" f"Sixes {I['six']}\n" f"{I['dismissal']}", inline=False) embed2 = discord.Embed(title=f"Bowling Team : {scorecard['bowlteam']}", colour=discord.Colour.gold()) for I in scorecard['bowlcard']: embed2.add_field(name=I['name'], value=f"Overs : {I['overs']}\n" f"Maidens : {I['maidens']}\n" f"Runs Given : {I['runs']}\n" f"Wickets Taken : {I['wickets']}\n" f"wides : {I['wides']}\n" f"no balls : {I['nballs']}", inline=False) await ctx.send(embed=embed1) await ctx.send(embed=embed2)
def scorecard(mid): result = [] c = Cricbuzz() scard = c.scorecard(mid) print(json.dumps(scard, indent=4, sort_keys=True)) result.append(scard) return jsonify({'scorecard': result})
def scoreCard(mid): """ To Fetch scorecard of a match""" c = Cricbuzz() matches = c.matches() my_data = [] for match in matches: if match['id'] == mid: game = c.scorecard(match['id']) status = game['matchinfo']['status'] desc = game['matchinfo']['mchdesc'] state = game['matchinfo']['mchstate'] print(colors("\n{} | {} | {}\n".format(desc, status, state), 33)) try: for i in range(2): wickets = game['scorecard'][i]['wickets'] runs = game['scorecard'][i]['runs'] bowlteam = game['scorecard'][i]['bowlteam'] overs = game['scorecard'][i]['overs'] batteam = game['scorecard'][i]['batteam'] runrate = game['scorecard'][i]['runrate'] print( colors( "\n{} - {} / {}({} Ovs)".format( batteam, runs, wickets, overs), 32)) sleep(1) print("\n--BATTING CARD--\n") battCard(game, i) sleep(1) print("\n--BOWLING CARD--\n") bowlCard(game, i) sleep(1) except IndexError: pass
def squad(mid): """ To display the squad for the individual teams available for the match""" header = ["S.no", "Player"] c = Cricbuzz() game = c.scorecard(mid) try: for i in range(2): my_data = [] squad = game['squad'][i]['members'] sq_team = game['squad'][i]['team'] print(colors("\n--{} Squad--\n".format(sq_team), 32)) counter = 1 for counter, member in enumerate(game['squad'][i]['members'], start=1): my_data.append([counter, member]) print(tabulate(my_data, headers=header, tablefmt="fancy_grid")) print("\n") sleep(1) except KeyError: game = c.commentary(mid) try: for i in range(1, 4): print("\n" + game['commentary'][i]) except (IndexError, KeyError): pass
def get(self, mid): c = Cricbuzz() dict = {} scorecard_required = c.scorecard(mid) dict['runs'] = scorecard_required['scorecard'][0]['runs'] dict['bowlteam'] = scorecard_required['scorecard'][0]['bowlteam'] dict['batteam'] = scorecard_required['scorecard'][0]['batteam'] dict['overs'] = scorecard_required['scorecard'][0]['overs'] dict['wickets'] = scorecard_required['scorecard'][0]['wickets'] return dict, 200
def alldetail(request, id): c = Cricbuzz() #print (c.scorecard(match['id'])) alldetail = c.scorecard(id) matches = c.matches() bat1 = 0 bowl1 = 0 fall_wickets1 = 0 #return JsonResponse({"alldetail":alldetail}) try: bat = alldetail['scorecard'][0]['batcard'] bowl = alldetail['scorecard'][0]['bowlcard'] fall_wickets = alldetail['scorecard'][0]['fall_wickets'] except: pass try: bat1 = alldetail['scorecard'][1]['batcard'] bowl1 = alldetail['scorecard'][1]['bowlcard'] fall_wickets1 = alldetail['scorecard'][1]['fall_wickets'] except: pass lscore = c.livescore(id) overin2 = 0 overin3 = 0 overin1 = 0 overin4 = 0 try: overin1 = lscore['batting']['score'][0]['overs'] overin3 = lscore['bowling']['score'][0]['overs'] overin2 = lscore['batting']['score'][1]['overs'] overin4 = lscore['bowling']['score'][1]['overs'] except: pass #return JsonResponse({"bat1":fall_wickets1}) return render( request, "cric/scorecard2.html", { "alldetail": alldetail, "bat": bat, "bowl": bowl, "fall_wickets": fall_wickets, "bat1": bat1, "bowl1": bowl1, "fall_wickets1": fall_wickets1, "lscore": lscore, "overin2": overin2, "overin3": overin3, "overin1": overin1, "overin4": overin4, "matches": matches, })
def index(): c = Cricbuzz() match = c.matches() mid = (match[0]['id']) livescore = c.livescore(mid=mid) scorecard = c.scorecard(mid=mid) matchinfo = c.matchinfo(mid=mid) commentary = c.commentary(mid=mid) result = {"matches": match, "livescore": livescore, "scorecard": scorecard, "matchinfo": matchinfo, "commentary": commentary} final = jsonify(result) return f"{final}"
def get_cricket_response(self, message: Dict[str, str], bot_handler: Any) -> str: content = message['content'] words = content.lower().split() c = Cricbuzz() matches = c.matches() val = "\n" + match + "\n" for match in matches: if (match['mchstate'] != 'nextlive'): val = val + c.livescore(match['id']) + "\n" val = val + c.commentary(match['id']) + "\n" val = val + c.scorecard(match['id']) + "\n" return val
def Scorecard(request, id): Z = Cricbuzz() m = Z.scorecard(str(id)) comm = Z.commentary(str(id)) if m['matchinfo']['mchstate'] == "Result": return test(request, m, comm) elif (m['matchinfo']['mchstate'] == "inprogress") or (m['matchinfo']['mchstate'] == "innings break"): if len(m['scorecard']) == 2: return test(request, m, comm) elif len(m['scorecard']) == 1: return test1(request, m, comm) return len(m)
def cricCommentry(): c = Cricbuzz() matches = c.matches() # for match in matches: match = matches[0] # print( match) if (match['mchstate'] != 'nextlive'): print(c.livescore(match['id'])) print(c.commentary(match['id'])) print(c.scorecard(match['id'])) print('sun', c.commentary(match['id'])['commentary'][0]['comm']) a, b = c.commentary(match['id'])['commentary'][0]['comm'], '' while (1): if (a != b): # speak(a) d = c.scorecard(match['id'])['scorecard'] print(a) print(d[0]['batteam'], 'score is ', d[0]['runs'], 'for', d[0]['wickets'], 'wickets') b = a else: a = c.commentary(match['id'])['commentary'][0]['comm']
def calculate_score(): #for batsman players = [] sixes = 0 fours = 0 runs = 0 balls_faced = 0 c = Cricbuzz() file = open('playerlist.txt', 'r') for line in file: players.append(line.strip()) print(players) matches = c.matches() score_card = c.scorecard(match['id'])
def refresh(): c = Cricbuzz() match = c.matches() mid = match[1]['id'] matches = match[1] livescore = c.livescore(mid=mid) scorecard = c.scorecard(mid=mid) matchinfo = c.matchinfo(mid=mid) commentary = c.commentary(mid=mid) result = {} result['matches'] = matches result['livescore'] = livescore result['scorecard'] = scorecard result['matchinfo'] = matchinfo result['commentary'] = commentary return result
def home_page(): c = Cricbuzz() all_matches = c.matches() for match in all_matches: if match['mchstate'] == 'inprogress' or match[ 'mchstate'] == 'innings break': mongo.db.inprogress.insert(match) mongo.db.inprogressmatchid.insert({"matchid": match['id']}) c.livescore(match['id'])['id'] = match['id'] mongo.db.inprogressscore.insert(c.livescore(match['id'])) mongo.db.inprogressscorecard.insert(c.scorecard(match['id'])) return render_template("index.html")
def cricket(): c = Cricbuzz() match = c.matches() mid = (match[0]['id']) livescore = c.livescore(mid=mid) scorecard = c.scorecard(mid=mid) matchinfo = c.matchinfo(mid=mid) commentary = c.commentary(mid=mid) result = [{ "matches": match, "livescore": livescore, "scorecard": scorecard, "matchinfo": matchinfo, "commentary": commentary }] return result
def send(mid): """ To send the notification about the live score update""" c = Cricbuzz() game = c.scorecard(mid) try: for i in range(1): wickets = game['scorecard'][i]['wickets'] runs = game['scorecard'][i]['runs'] bowlteam = game['scorecard'][i]['bowlteam'] overs = game['scorecard'][i]['overs'] batteam = game['scorecard'][i]['batteam'] runrate = game['scorecard'][i]['runrate'] message = "{} - {} / {}( {} Ovs )".format(batteam, runs, wickets, overs) except IndexError: pass s.call(['notify-send', message]) sleep(60)
def score(self): self.raina.setText(ui.totalaffected) c=Cricbuzz() matches=c.matches() finalscorecard="" ui.selectedmatch=self.livematches.currentText() if ui.selectedmatch!="": for match in matches: if ui.selectedmatch in match['mchdesc']: identity=match['id'] finalscorecard=finalscorecard+str(match['srs']) finalscorecard=finalscorecard+"\n"+str(match['mchdesc']) finalscorecard=finalscorecard+"\n"+str(match['type'])+str(match['mnum']) finalscorecard=finalscorecard+"\n"+str(match['status']) scorecard=c.scorecard(identity) seperator="-------------------------------------------------------------------------------" finalscorecard=finalscorecard+"\n"+seperator finalscorecard=finalscorecard+"\n"+"BATTING TEAM :"+str(scorecard['scorecard'][0]['batteam']) for i in range(len(scorecard['scorecard'][0]['batcard'])): temp="" temp=str(scorecard['scorecard'][0]['batcard'][i]['name'])+" "+str(scorecard['scorecard'][0]['batcard'][i]['runs'])+"of"+str(scorecard['scorecard'][0]['batcard'][i]['balls'])+", Fours :"+str(scorecard['scorecard'][0]['batcard'][i]['fours'])+", Sixes :"+str(scorecard['scorecard'][0]['batcard'][i]['six'])+", Dismissal :"+str(scorecard['scorecard'][0]['batcard'][i]['dismissal']) finalscorecard=finalscorecard+"\n"+temp finalscorecard=finalscorecard+"\n"+"Score :"+str(scorecard['scorecard'][0]['runs'])+"/"+str(scorecard['scorecard'][0]['wickets']) finalscorecard=finalscorecard+"\n"+"Runrate :"+str(scorecard['scorecard'][0]['runrate']) finalscorecard=finalscorecard+"\n"+seperator finalscorecard=finalscorecard+"\n"+"BOWLING TEAM :"+str(scorecard['scorecard'][0]['bowlteam']) for i in range(len(scorecard['scorecard'][0]['bowlcard'])): temp="" temp=str(scorecard['scorecard'][0]['bowlcard'][i]['name'])+"Overs :"+str(scorecard['scorecard'][0]['bowlcard'][i]['overs'])+", Runs :"+str(scorecard['scorecard'][0]['bowlcard'][i]['runs'])+", Wickets :"+str(scorecard['scorecard'][0]['bowlcard'][i]['wickets']) finalscorecard=finalscorecard+"\n"+temp self.label_3.setText(finalscorecard) self.label_3.show()==True else: self.label_3.setText("Select the Live Match ") self.label_3.show()==True
# -*- coding: utf-8 -*- """ Created on Mon Apr 09 11:01:13 2018 @author: Dhairyya """ from pycricbuzz import Cricbuzz import sys import sqlite3 c=Cricbuzz() matches=c.matches() match=matches[1] scorecard=c.scorecard(match['id']) data=scorecard['scorecard'] ################################################################# connection=sqlite3.connect("myTable.db") crsr=connection.cursor() ################################################################### ##################################################################### #Bowling ##################################################################### for i in range(0,2): wicketsTakenByTeam=float(data[i]['wickets']) runsGivenByTeam=float(data[i]['runs']) bowlingData=data[i]['bowlcard']
print("\n\nBOWLING\n") print(df_bowl) # In[4]: #Here is the main calling of the program and both the functions are called in appropriate order k=1 for i in cb.matches(): print("\n\n") print("############################################## MATCH ",k," ###################################################") print("\n\n") matchInfo(i) try: scorecard(cb.scorecard(i['id'])) #cb.livescore(i['id']) except: pass k+=1 # In[ ]:
from pycricbuzz import Cricbuzz import json from pprint import pprint f = open('output.txt','w') c = Cricbuzz() matches = c.matches() scorecard = c.scorecard(18775) # pprint(scorecard) for i in range(len(matches)): print('Match: ',end='') print(matches[i]['mchdesc']) print('Result: ',end='') print(matches[i]['status'],end='') print('\n') ''' print(json.dumps(matches,indent=4),file=f) '''
#pip install pycricbuzz from pycricbuzz import Cricbuzz a = Cricbuzz() match = a.matches() for x in match: print(x) if (x['mchstate'] != 'nextlive'): print(a.livescore(x['id'])) print(a.commentary(x['id'])) print(a.scorecard(x['id']))
class Cricket(): """ Enter cricket and follow the instructions """ def __init__(self): self.c = Cricbuzz() def __call__(self, jarvis, s): self._refresh(jarvis) self.score(jarvis) def _refresh(self, jarvis): spinner = SpinnerThread('Fetching ', 0.15) spinner.start() 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()) spinner.stop() jarvis.say('DONE fetching match details', Fore.GREEN) 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 True: try: choice = int(jarvis.input('\nEnter choice (number): ', Fore.RED)) while choice < 1 or choice > len(self.matches): print(Fore.BLACK + '\nWrong choice') choice = int(jarvis.input('\nEnter choice again: ', Fore.RED)) 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 True: try: choice = int(jarvis.input('\nEnter choice (number): ', Fore.RED)) while choice < 1 or choice > 4: print(Fore.BLACK + '\nWrong choice') choice = int(jarvis.input('\nEnter choice again: ', Fore.RED)) break except ValueError: print("Invalid type of choice. Please enter an integer number") print('') if choice == 1: print(self.scorecard(selected_match_id)) ref = jarvis.input('Do you want to refresh:(y/n) ', Fore.RED) while ref == 'y': print(self.scorecard(selected_match_id)) ref = jarvis.input('Do you want to refresh:(y/n) ', Fore.RED) elif choice == 2: print(self.commentary(selected_match_id)) ref = jarvis.input('Do you want to refresh:(y/n) ', Fore.RED) while ref == 'y': print(self.commentary(selected_match_id)) ref = jarvis.input('Do you want to refresh:(y/n) ', Fore.RED) elif choice == 3: ref = 'y' while ref == 'y': print(self.live_score(selected_match_id)) ref = jarvis.input('Do you want to refresh:(y/n) ', Fore.RED) else: return
from pycricbuzz import Cricbuzz import json c = Cricbuzz() matches = c.matches() for match in matches: print (json.dumps(c.scorecard(match['id']),indent=4)) break
if ('IND ' in match['mchdesc']): print(match['id']) #Get the feed for your team print() finalscorecard = "" for match in matches: if 'IND vs PAK' in match['mchdesc']: identity = match['id'] finalscorecard = finalscorecard + str(match['srs']) finalscorecard = finalscorecard + "\n" + str(match['mchdesc']) finalscorecard = finalscorecard + "\n" + str(match['type']) + str( match['mnum']) finalscorecard = finalscorecard + "\n" + str(match['status']) finalscorecard = finalscorecard + "\n" + str(match['mchstate']) scorecard = c.scorecard(identity) seperator = "-------------------------------------------------------------------------------" finalscorecard = finalscorecard + "\n" + seperator finalscorecard = finalscorecard + "\n" + "BATTING TEAM :" + str( scorecard['scorecard'][0]['batteam']) for i in range(len(scorecard['scorecard'][0]['batcard'])): temp = "" temp = str( scorecard['scorecard'][0]['batcard'][i]['name']) + " " + str( scorecard['scorecard'][0]['batcard'][i] ['runs']) + "of" + str( scorecard['scorecard'][0]['batcard'][i]['balls'] ) + ", Fours :" + str( scorecard['scorecard'][0]['batcard'][i]['fours'] ) + ", Sixes :" + str( scorecard['scorecard'][0]['batcard'][i]['six']
from tkinter import * from pycricbuzz import Cricbuzz root = Tk() root.title("live cricket score") root.geometry("800x800") c = Cricbuzz() match = c.matches() score = c.livescore(match[0]['id']) commentary = c.commentary(match[0]['id']) score_board = c.scorecard(match[0]['id']) for a in score: print(a) for b in score[a]: print(b, ':', score[a][b]) s = str(score_board) k = s.replace(",", "\n") score1 = Label(root, font=("time", 15, "bold"), bg="white", text=k) score1.grid(row=2, column=2, pady=25, padx=100) print(commentary) root.mainloop()
def scorecard(mid): c = Cricbuzz() scard = c.scorecard(mid) print(json.dumps(scard, indent=4, sort_keys=True))
class Cricket: def __init__(self): self.cb = Cricbuzz() self.all_matches = self.cb.matches() self.run = True def live_matches(self): msg = "* 🏏 All live matches *\n\n" for match in self.all_matches: if match['mchstate'] == 'inprogress': msg += match["team1"]["name"]+" v/s " + match["team2"]["name"]+ "," \ + match["srs"] + " - " + match["mnum"] + "\n\n" else: msg += "No live matches" return msg def commentary(self, match_id): commentary = self.cb.commentary(match_id) msg = f"Live commentary - {match_id}\n\n" for com in commentary["commentary"]: msg += com['comm'].replace("<b>","").replace("</b>","").replace("<br/>","\n") + "\n" return msg def score_card(self, match_id): match = self.cb.matchinfo(match_id) score = self.cb.scorecard(match_id) msg = f"<code>{match['team1']['name']} v/s {match['team2']['name']}-Scorecard</code>\n" for scr in reversed(score["scorecard"]): batcard = "".join([f"Name: {batcard['name']}\n Runs: {batcard['runs']}\n Balls: {batcard['balls']}\n Fours: {batcard['fours']}\n Six: {batcard['six']}\n Dismissal: {batcard['dismissal']}\n" for batcard in scr['batcard']]) bowlcard = "".join([f"Name: {bowlcard['name']}\n Overs: {bowlcard['overs']}\n Maidens: {bowlcard['maidens']}\n Runs: {bowlcard['runs']}\n Six: {bowlcard['wickets']}\n Wides: {bowlcard['wides']}\n No Balls: {bowlcard['nballs']}\n" for bowlcard in scr['bowlcard']]) msg += f"INN: {scr['inng_num']}\n" \ f" Batteam: {scr['batteam']}\n" \ f" {scr['runs']}/{scr['wickets']} in {scr['overs']} overs\n" \ f" Bowlteam: {scr['bowlteam']}\n" \ "\n\n" return msg def players(self, match_id): match = self.cb.matchinfo(match_id) msg = f'Team 1: {match["team1"]["name"]}\n' msg += "Squad:\n " + " ".join([squad + "\n" for squad in match["team1"]["squad"]]) msg += f'\n\nTeam 2: {match["team2"]["name"]}\n' msg += "Squad:\n " + " ".join([squad + "\n" for squad in match["team2"]["squad"]]) return msg def match_info(self, match_id): match = self.cb.matchinfo(match_id) msg = "*Series:* _" + match["srs"] + "_\n" \ "*Match No:* _" + match["mnum"] + "_\n" \ "*Type:* _" + match["type"] + "_\n" \ "*State:* _" + match["mchstate"] + "_\n" \ "*Status:* _" + match["status"] +"_\n" \ "*Venue:* _" + match["venue_name"] + " " + match["venue_location"] + "_\n" \ "*Toss:* _" + match["toss"] + "_\n" \ "*Team 1:* _" + match["team1"]["name"] + "_\n" \ "*Team 2:* _" + match["team2"]["name"] + "_\n" \ f"*Officials:*\n _umpire 1: {match['official']['umpire1']['name']}\n umpire 2: {match['official']['umpire2']['name']}\n umpire 3: {match['official']['umpire3']['name']}\n referee: {match['official']['referee']['name']}_\n" \ "*Start Time:* _" + match["start_time"] + "_\n" \ "*Team 1:* _" + match["team1"]["name"] + "_\n" \ "*Team 2:* _" + match["team2"]["name"] + "_\n" return msg def live_score(self, message, match_id): then = time.time() while self.run: elapsed = time.time() - then if elapsed > 10800: message.delete() break match_info = self.cb.matchinfo(match_id) live_score = self.cb.livescore(match_id) last_updated = datetime.utcnow() + timedelta(minutes=30, hours=5) batting, bowling = live_score["batting"], live_score["bowling"] msg = '' msg += match_info['srs'] + '\n' + match_info['status'] + '\n\n' msg += batting['team'] + "\n" for score in batting['score']: msg += f" INN: {score['inning_num']} {score['runs']}/{score['wickets']} in {score['overs']} overs\n" for bts in batting['batsman']: msg += f" {bts['name']} : {bts['runs']}({bts['balls']}) \n" msg += bowling['team'] + "\n" for score in bowling['score']: msg += f" INN: {score['inning_num']} {score['runs']}/{score['wickets']} in {score['overs']} overs\n" for balls in bowling['bowler']: msg += f" {balls['name'].strip('*')} : {balls['wickets']}/{balls['runs']} \n" msg += f"\n_Last updated: {last_updated.strftime('%I:%M:%S %P')} [IST]_" try: message.edit_text( text = msg, parse_mode="markdown", reply_markup = InlineKeyboardMarkup([ [ InlineKeyboardButton(text=f"Stop",callback_data=f"stop"), InlineKeyboardButton(text=f"Force Refresh",callback_data=f"force_ref-{match_id}") ] ]) ) except: pass time.sleep(60) else: self.run = True message.edit_text("Terminating...") time.sleep(2) message.delete() def list_matches_buttons(self, cb_data): btns = [] for match in self.all_matches: btns.append([InlineKeyboardButton(text=f" {match['team1']['name']} v/s {match['team2']['name']} ",callback_data=f"{cb_data}-{match['id']}")]) btns.append([ InlineKeyboardButton(text=f"<<< Go back to home",callback_data=f"back_to_home")]) return btns
from pycricbuzz import Cricbuzz c = Cricbuzz() matches = c.matches() for match in matches: print(match) if(match['mchstate'] != 'nextlive'): print(c.livescore(match['id'])) print(c.commentary(match['id'])) print(c.scorecard(match['id']))
# before executing the code install the "pycricbuzz" package # use "pip install pycricbuzz" or "pip3 install pycricbuzz" from pycricbuzz import Cricbuzz import json c = Cricbuzz() # create a cricbuzz object matches = c.matches() for match in matches: print(match) print(c.livescore(match['id'])) # fetches the lievscore print(c.commentary(match['id'])) # fetch the commentary of the match print(c.scorecard(match['id'])) # fetch the scorecard of the match
class Cricket(Plugin): """ Enter cricket and follow the instructions """ def __init__(self): self.c = Cricbuzz() def require(self): yield ('network', True) def complete(self): pass def alias(self): pass def run(self, jarvis, s): self.score(jarvis) def match_id(self, desc): all_matches = self.c.matches() for match in all_matches: if match['mchdesc'].title() == desc: return match['id'] else: return None def all_matches(self): match_data = self.c.matches() matches = [] for match in match_data: matches.append(match['mchdesc']) return matches def live_score(self, desc): mid = self.match_id(desc) res = self.c.matches() for value in res: if value['id'] == mid: if value['mchstate'] == 'preview': text = Fore.RED + "MATCH YET TO BEGIN" return text data = self.c.livescore(mid) score = {} score['matchinfo'] = "{}, {}".format(data['matchinfo']['mnum'], data['matchinfo']['mchdesc']) score['status'] = "{}, {}".format( data['matchinfo']['mchstate'].title(), data['matchinfo']['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'] + '\n' + Fore.BLACK for scr in reversed(score['batting']['score']): text += "{} :- {}/{} in {} overs\n".format(scr['desc'], 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'] + '\n' + Fore.BLACK for scr in reversed(score['bowling']['score']): text += "{} :- {}/{} in {} overs\n".format(scr['desc'], 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, desc): mid = self.match_id(desc) data = self.c.commentary(mid) comm = {} comm['matchinfo'] = "{}, {}".format(data['matchinfo']['mnum'], data['matchinfo']['mchdesc']) comm['status'] = "{}, {}".format(data['matchinfo']['mchstate'].title(), data['matchinfo']['status']) comm['commentary'] = data['commentary'] text = '' text += Fore.LIGHTYELLOW_EX + comm['matchinfo'] + '\n' + comm[ 'status'] + '\n\n' + Fore.RESET for com in comm['commentary']: text += "{}\n\n".format(com) return text def scorecard(self, desc): mid = self.match_id(desc) data = self.c.scorecard(mid) card = {} card['matchinfo'] = "{}, {}".format(data['matchinfo']['mnum'], data['matchinfo']['mchdesc']) card['status'] = "{}, {}".format(data['matchinfo']['mchstate'].title(), data['matchinfo']['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 + "{} {}\n{}/{} in {} overs\n\n".format( scr['batteam'], scr['inngdesc'], 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): matches = self.all_matches() jarvis.say(Fore.RED + "\nALL MATCHES\n" + Fore.LIGHTBLUE_EX) if matches == []: jarvis.say("No Matches Being Played!\n", Fore.RED) return for i, m in enumerate(matches, 1): jarvis.say("{}. {}".format(str(i), m)) choice = int(input(Fore.RED + '\nEnter choice (number): ' + Fore.RESET)) while choice < 1 or choice > len(matches): jarvis.say(Fore.BLACK + '\nWrong choice') choice = int( input(Fore.RED + '\nEnter choice again: ' + Fore.RESET)) desc = matches[choice - 1].title() jarvis.say('') res = self.live_score(desc) jarvis.say(res) jarvis.say("\n") if (res == Fore.RED + "MATCH YET TO BEGIN"): return jarvis.say(self.live_score(desc)) jarvis.say(Fore.LIGHTBLUE_EX + '1. Full Score Card') jarvis.say('2. Commentary') jarvis.say('3. Refresh Score') jarvis.say('4. Quit' + Fore.RESET) choice = int(input(Fore.RED + '\nEnter choice (number): ' + Fore.RESET)) while choice < 1 or choice > 4: jarvis.say(Fore.BLACK + '\nWrong choice') choice = int( input(Fore.RED + '\nEnter choice again: ' + Fore.RESET)) jarvis.say('') if choice == 1: ref = 'y' while ref == 'y': jarvis.say(self.scorecard(desc)) ref = input(Fore.RED + 'Do you want to refresh:(y/n) ' + Fore.RESET) jarvis.say('\n') elif choice == 2: ref = 'y' while ref == 'y': jarvis.say(self.commentary(desc)) ref = input(Fore.RED + 'Do you want to refresh:(y/n) ' + Fore.RESET) jarvis.say('\n') elif choice == 3: ref = 'y' while ref == 'y': jarvis.say(self.live_score(desc)) ref = input(Fore.RED + 'Do you want to refresh:(y/n) ' + Fore.RESET) jarvis.say('\n')
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)) ref = input(Fore.RED + 'Do you want to refresh:(y/n) ' + Fore.RESET) else: return
#please install pycricbuzz pakage before running this program from pycricbuzz import Cricbuzz c = Cricbuzz() matches = c.matches() for match in matches: print(match) if (match['mchstate'] != 'nextlive'): print(c.livescore(match['id'])) print(c.commentary(match['id'])) print(c.scorecard(match['id']), end="")