From 4daff2bf62e12b6ce18413fecf7b5872e0c258e1 Mon Sep 17 00:00:00 2001 From: Aditya <2005akjha@gmail.com> Date: Tue, 28 May 2024 13:39:24 +0530 Subject: [PATCH] added cricket score feature --- __pycache__/cricscore.cpython-312.pyc | Bin 0 -> 3938 bytes cricscore.py | 99 ++++++++++++++++++++++++++ daisy_main.py | 9 ++- 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 __pycache__/cricscore.cpython-312.pyc create mode 100644 cricscore.py diff --git a/__pycache__/cricscore.cpython-312.pyc b/__pycache__/cricscore.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..38fbd1737dbc7ea6bedc4f4041b77bc1f2b252e2 GIT binary patch literal 3938 zcma)7TWs6b89tOqT`9}5C|_h-qAc06nnX@)C(gZf;oV+i!!^zjW)o{Kq8>3#OTWPDmEDOO19tR>a`BpMBnG_``v@Ai1dt6{RU;b(Mby&H1PGBv4MK!*dW{WNBSOK*G6BO!J2m~ z+hu5DXvUWwg#q+OfIx14$D13clVI7jgk1yk=1Fi3LwaGP=VcO@%ap|;XHaj)_*NEoReUtXo}OC zlSL{5m)8T)@GAw5E%rMcXR;C$=#1{4&K5EsqD@YqVNJT9mU1+l=cJ>>=(+4%lIPfG zG~@K!JWPs^mV^a5c_qnZL&aW0k;~=_(vC(QFuCm_R5Upp8hHF)^k{^{NjxkDPUo^& zn9`%8Ur%y;L4a}k(hjhOIW&yk!Undm{w*xFh3$Pzp!|xK(HT8~qMgpoK|zei0u6v-9MwIdb^Sy5}=*v<71 z2U@d`*y$vp9rSweu#Sf#0;NHN}9_EsV=qDuHu5`K;hOS z7d3Zd>gttkzLd+2C$kF|Aj=789L2A|_o!!J>+RIhsmrJ_;#B%-GRaQ8m4#!1euwv= z+neR`NuIu(MSDTyqy_qXlFJu_sWB+dO1b>h7^>dF=(#EV;?_zL&o6A*j%RXgfrlrB zH<1JVwu*m3GgmcZ81@}-KLXv~0mmZ{cm!Ji35c>KxDMzIo#|c&0o8JF(X8Uli)VkG z_%yNXRdC-Twqd1~-?=q$b7Eyeu|^j0O`KT7RGVXwP|4;SiR+1#R)wUW0yE}Z9NWO{ z*TbdcZ~B&pukTxl+=<ep4{ea1a?7!G@;K7kBt2CpaJ5zK!0LSBN6?Ei zpSd>M{bk@&n_CuLs@GQr&1zlX@h&!P>P`<4E|uz7d1dvZ+i{tSmFz0nUOHRLyF($v zC2YgpwerrLiQ5ya6N-Cp30Iq`TjWi0<>yLsZ;7blxZS6ct_m5D$-p{EqonBY>cKV7 z-NRp=xO+kg9w^(oRA;apKCCzo*8=WaqvV!->ttMw94?cgO@F-NAC~>Y_b)2`Bc-3A zI7?${YkTPpwX?gFQ2o760pap5TU2lBO5g8JY;*=z=I(ra`{T9KN^t*uj~pDT1dqtU zBTDd?(s_J&Y$Fg_?fY`?-Mwp~(lc~_RPH%c={YX<99McyDuGv*-`EKEt^V@wTCUx$^*NtCNf z#nwVHwYNeI%GBWfA%zdI3^y&fG8(G61dSfaTT~1V}s7yuGK;Kv1wfB|S zF*$JT>sdK)PNj#{&_R_B{o79XTB{`J89=ZUARML8XJ?;?7#f@ZRNDaA`V?Sj5^b(> z)4_`E5V~5#$Pd+i(A@D9nC!k<3kTQ9p+_Y3LzO_1AF7uyKvETFKz0Ty&baK1>kzID z8@cK98sY)jIbeu&OxKn;g|6>kT8<}7;IDlr69>RIz0HYM@Xf(d8`}KsroUT>MBMzK)0T*tAB1uJG**+u%{qUeV?1j92idN_`!MwWA1mI-rT_o{ literal 0 HcmV?d00001 diff --git a/cricscore.py b/cricscore.py new file mode 100644 index 0000000..3f3297a --- /dev/null +++ b/cricscore.py @@ -0,0 +1,99 @@ +import requests +from bs4 import BeautifulSoup +import sys +from plyer import notification +from time import sleep + +print("\nLive Cricket Matches:") +print("=====================") +url = "http://static.cricinfo.com/rss/livescores.xml" +r = requests.get(url) +soup = BeautifulSoup(r.text, "lxml") + +i = 1 +links = [] +for item in soup.findAll("item"): + print(str(i) + ". " + item.find("description").text) + links.append(item.find("guid").text) + i += 1 + +print("\n\nEnter match number or enter 0 to exit:") +while True: + try: + user_input = int(input()) + if user_input == 0: + sys.exit() + elif user_input < 0 or user_input > len(links): + print("Invalid match number. Please try again!") + continue + else: + break + except ValueError: + print("Invalid input. Please enter a number!") + +print("\n\n") + +previous_score_string = "" +previous_runs = -1 +previous_wickets = -1 +previous_batting_team = "" +previous_overs = -1 # Initialize to -1 + +while True: + try: + match_url = links[user_input - 1] + r = requests.get(match_url) + soup = BeautifulSoup(r.text, "lxml") + score = soup.findAll("title") + + try: + r.raise_for_status() + except Exception as exc: + print("Connection Failure. Try again!") + continue + + current_score_string = str(score[0].text) + if current_score_string != previous_score_string: + print(current_score_string + "\n") + previous_score_string = current_score_string + + score_split = current_score_string.split(" ") + runs = -1 + wickets = -1 + batting_team = "" + for string in score_split: + if "/" in string: + runs = int(string.split("/")[0].strip()) + wickets = int(string.split("/")[1].strip()) + batting_team = str(score_split[score_split.index(string) - 1]).strip() + break + + detailed_scores = (current_score_string[current_score_string.find("(") + 1 : current_score_string.find(")")]).strip() + detailed_scores_split = detailed_scores.split(",") + overs = detailed_scores_split[0].split(" ")[0].strip() + + if previous_overs == -1: + previous_overs = int(float(overs)) # Initialize to the current value of overs + + # Convert overs to float to handle cases like "10.2" + current_overs = int(float(overs)) + + if current_overs != previous_overs: + if current_overs % 5 == 0: # Notify after every 5 overs + notification.notify( + title="After " + str(current_overs) + " overs...", + message=current_score_string, + app_name="Live Cricket Score", + timeout=5 + ) + previous_overs = current_overs + + # Rest of your code for handling notifications based on score updates... + + except requests.exceptions.ConnectionError: + pass + + except requests.exceptions.TooManyRedirects: + pass + + sleep(5) # Wait for 5 seconds before polling again diff --git a/daisy_main.py b/daisy_main.py index 35e6b7c..a9e87af 100644 --- a/daisy_main.py +++ b/daisy_main.py @@ -13,6 +13,7 @@ from plyer import notification from pygame import mixer import speedtest +from pycricbuzz import Cricbuzz for(i) in range(3): @@ -174,6 +175,12 @@ def convert_to_datetime(alarm_time_str): print(f"Ping is {ping} ms") speak(f"Ping is {ping} ms") + elif "cricket score" in query: + from cricscore import cricscore + cricscore() + + + elif "hello" in query: @@ -323,4 +330,4 @@ def convert_to_datetime(alarm_time_str): os.system("shutdown /s /t 1") elif "no" in shutdown: speak("Shutdown cancelled") - break + break \ No newline at end of file