Cricket Score Updater Script

This is the place to post any code that you want to share with the community. Only completed scripts should be posted here.
Note: posts here are not necessarily endorsed by the community, and may represent amateur or even bad practices.

Cricket Score Updater Script

Postby sagarvk90 » Tue Apr 05, 2016 4:26 pm

I have made a script to update the cricket score by select the on going going matches. Follow are the screen shots of the scripts.


Image

Image

Code: Select all
import sys
import requests
import time
from PySide import QtCore, QtGui
from bs4 import BeautifulSoup
from time import sleep
I1 = []
I2 = []
Links=[]
MInfo=[]


class SystemTrayIcon(QtGui.QSystemTrayIcon):

    def __init__(self, icon, parent=None):
        QtGui.QSystemTrayIcon.__init__(self, icon, parent)
        menu = QtGui.QMenu(parent)
        url = "http://www.espncricinfo.com/ci/engine/match/index.html?view=live"
        r = requests.get(url)
        soup = BeautifulSoup(r.content,"html.parser")
        inng1 = soup.find_all("div",{"class":"innings-info-1"})
        inng2= soup.find_all("div",{"class":"innings-info-2"})
       
        for item in inng1:
                I1.append(item.text.rstrip())
        for item in inng2:
                I2.append(item.text.lstrip())
        for l1,l2 in zip(I1,I2):
            MInfo.append(l1+ " Vs. " +l2)

        data = soup.find_all("div",{"class":"match-articles"})
        for item in data:
                scr1=item.find_all("a")
                Links.append("http://www.espncricinfo.com"+ scr1[0].get("href"))
           
        for item in MInfo:
            action = menu.addAction(item)
            self.setContextMenu(menu)
            action.triggered[()].connect(
            lambda item=item: self.getScore(item))
       
       
    def getScore(self,item):
       
       
        newmenu1 = QtGui.QMenu()
        newmenu2 = QtGui.QMenu()
        icon = QtGui.QIcon("C:\Python34\C.png")
        i=MInfo.index(item)
        url=(Links[i])

        while True:
            II1=[]
            II2=[]
            r = requests.get(url)
            soup = BeautifulSoup(r.content,"html.parser")
       
            team1 = soup.find_all("div",{"class":"team-1-name"})
            team2 = soup.find_all("div",{"class":"team-2-name"})
            TOSS = soup.find_all("div",{"class":"innings-requirement"})
           
           

            urlmain = "http://www.espncricinfo.com/ci/engine/match/index.html?view=live"
            r1 = requests.get(urlmain)
           
            soup1 = BeautifulSoup(r1.content,"html.parser")
            inng1 = soup1.find_all("div",{"class":"innings-info-1"})
            inng2 = soup1.find_all("div",{"class":"innings-info-2"})
           
               
            for item in inng1:
                II1.append(item.text.rstrip())
            for item in inng2:
                II2.append(item.text.lstrip())
            innings1=II1[i].replace(team1[0].text,'')

            if any(word in team1[0].text for word in II1[i]):
                innings1=II1[i].replace(team1[0].text,'')
                print(innings1)
                TEAM1SCORE = team1[0].text.rstrip() + " : " + innings1.lstrip()
                innings2=II2[i].replace(team2[0].text,'')
                if innings2=="":
                    TEAM2SCORE=""
                else:
                    TEAM2SCORE = team2[0].text.rstrip() + " : " + innings2.lstrip()
               
            else:
                innings1=II1[i].replace(team2[0].text,'')
                TEAM1SCORE = team2[0].text + " : " + innings1.lstrip()
                innings2=II2[i].replace(team1[0].text,'')
                if innings2=="":
                    TEAM2SCORE=""
                else:
                    TEAM2SCORE = team1[0].text.rstrip() + " : " + innings2.lstrip()

            self.tray = QtGui.QSystemTrayIcon()
            self.tray.setIcon(icon)
            self.tray.setContextMenu(newmenu1)
            self.tray.show()
            self.tray.showMessage("Live Cricket Score","\n" + TEAM1SCORE + "\n" + TEAM2SCORE + "\n"+ TOSS[0].text.lstrip()  )
           
            sleep(15)

def main():
    app = QtGui.QApplication(sys.argv)

    w = QtGui.QWidget()
    trayIcon = SystemTrayIcon(QtGui.QIcon("C:\Python34\C.png"), w)

    trayIcon.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()


https://github.com/sagarvk/Python/tree/master/Live-Cricket
sagarvk90
 
Posts: 2
Joined: Sun Feb 28, 2016 7:46 am

Re: Cricket Score Updater Script

Postby micseydel » Tue Apr 05, 2016 4:45 pm

Thanks for sharing!
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Cricket Score Updater Script

Postby RavinderSingh13 » Sun Jun 12, 2016 2:39 pm

sagarvk90 wrote:I have made a script to update the cricket score by select the on going going matches. Follow are the screen shots of the scripts.


Image

Image

Code: Select all
import sys
import requests
import time
from PySide import QtCore, QtGui
from bs4 import BeautifulSoup
from time import sleep
I1 = []
I2 = []
Links=[]
MInfo=[]


class SystemTrayIcon(QtGui.QSystemTrayIcon):

    def __init__(self, icon, parent=None):
        QtGui.QSystemTrayIcon.__init__(self, icon, parent)
        menu = QtGui.QMenu(parent)
        url = "http://www.espncricinfo.com/ci/engine/match/index.html?view=live"
        r = requests.get(url)
        soup = BeautifulSoup(r.content,"html.parser")
        inng1 = soup.find_all("div",{"class":"innings-info-1"})
        inng2= soup.find_all("div",{"class":"innings-info-2"})
       
        for item in inng1:
                I1.append(item.text.rstrip())
        for item in inng2:
                I2.append(item.text.lstrip())
        for l1,l2 in zip(I1,I2):
            MInfo.append(l1+ " Vs. " +l2)

        data = soup.find_all("div",{"class":"match-articles"})
        for item in data:
                scr1=item.find_all("a")
                Links.append("http://www.espncricinfo.com"+ scr1[0].get("href"))
           
        for item in MInfo:
            action = menu.addAction(item)
            self.setContextMenu(menu)
            action.triggered[()].connect(
            lambda item=item: self.getScore(item))
       
       
    def getScore(self,item):
       
       
        newmenu1 = QtGui.QMenu()
        newmenu2 = QtGui.QMenu()
        icon = QtGui.QIcon("C:\Python34\C.png")
        i=MInfo.index(item)
        url=(Links[i])

        while True:
            II1=[]
            II2=[]
            r = requests.get(url)
            soup = BeautifulSoup(r.content,"html.parser")
       
            team1 = soup.find_all("div",{"class":"team-1-name"})
            team2 = soup.find_all("div",{"class":"team-2-name"})
            TOSS = soup.find_all("div",{"class":"innings-requirement"})
           
           

            urlmain = "http://www.espncricinfo.com/ci/engine/match/index.html?view=live"
            r1 = requests.get(urlmain)
           
            soup1 = BeautifulSoup(r1.content,"html.parser")
            inng1 = soup1.find_all("div",{"class":"innings-info-1"})
            inng2 = soup1.find_all("div",{"class":"innings-info-2"})
           
               
            for item in inng1:
                II1.append(item.text.rstrip())
            for item in inng2:
                II2.append(item.text.lstrip())
            innings1=II1[i].replace(team1[0].text,'')

            if any(word in team1[0].text for word in II1[i]):
                innings1=II1[i].replace(team1[0].text,'')
                print(innings1)
                TEAM1SCORE = team1[0].text.rstrip() + " : " + innings1.lstrip()
                innings2=II2[i].replace(team2[0].text,'')
                if innings2=="":
                    TEAM2SCORE=""
                else:
                    TEAM2SCORE = team2[0].text.rstrip() + " : " + innings2.lstrip()
               
            else:
                innings1=II1[i].replace(team2[0].text,'')
                TEAM1SCORE = team2[0].text + " : " + innings1.lstrip()
                innings2=II2[i].replace(team1[0].text,'')
                if innings2=="":
                    TEAM2SCORE=""
                else:
                    TEAM2SCORE = team1[0].text.rstrip() + " : " + innings2.lstrip()

            self.tray = QtGui.QSystemTrayIcon()
            self.tray.setIcon(icon)
            self.tray.setContextMenu(newmenu1)
            self.tray.show()
            self.tray.showMessage("Live Cricket Score","\n" + TEAM1SCORE + "\n" + TEAM2SCORE + "\n"+ TOSS[0].text.lstrip()  )
           
            sleep(15)

def main():
    app = QtGui.QApplication(sys.argv)

    w = QtGui.QWidget()
    trayIcon = SystemTrayIcon(QtGui.QIcon("C:\Python34\C.png"), w)

    trayIcon.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()


https://github.com/sagarvk/Python/tree/master/Live-Cricket

Hello sagarvk90,

Thank you for the great script. I have following requests to you on same.

i- Could you please let me know about it's working. I simply have installed ll it's modues into my system but when I run script it simply runs NOT showing any updates.
ii- Could you please add a sheet for the explanation of your code so that new comers like me could learn it too, will be grateful to you sir.


Thanks,
R. Singh
RavinderSingh13
 
Posts: 7
Joined: Sun Jun 12, 2016 1:16 pm

Re: Cricket Score Updater Script

Postby RavinderSingh13 » Fri Jul 08, 2016 8:40 am

Hello Dear experts,

Greetings !!

I apologies for asking question again here, I am really interested to learn this program very eagerly even I tried googling too. I would be grateful to you guys if you could explain me the same.

Thanks,
R. Singh
RavinderSingh13
 
Posts: 7
Joined: Sun Jun 12, 2016 1:16 pm


Return to Completed Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

cron