Ejemplo n.º 1
0
def getLiveScoreText(iFrameLink):
	returnText=["","",""]
	returnText[1]="***\n\n|Team|Score|\n|:---|:---|"
	soup = returnSoup(iFrameLink)
	for Table in soup.find_all(class_="desktopPanelContent"):
		returnText[1]=returnText[1]+HTMLTableToPythonTable(Table)[1]+"\n\n"
		returnText[2]=returnText[2]+HTMLTableToPythonTable(Table)[2]
	index=returnText[1].find("|Batsmen|R|B|4s|6s|")+len("|Batsmen|R|B|4s|6s|")
	finalReturnText=returnText[1][:index]+"\n|:---|:---|:---|:---|:---|"+returnText[1][index:]
	finalReturnText=finalReturnText + returnText[2]
	finalReturnText=finalReturnText+"***"
	return finalReturnText
Ejemplo n.º 2
0
def returnStatsPerPlayer(player,oppositionTeamName,format):
	playerId=re.findall('\d+\.html', player)[0]
	returnString="|" + player + "|"
	country_codes = {
	'afghanistan' : 40,
	'australia' : 2,
	'bangladesh' : 25,
	'bermuda' : 12,
	'england' : 1,
	'hong kong' : 19,
	'india' : 6,
	'ireland' : 29,
	'netherlands' : 15,
	'new zealand' : 5,
	'pakistan' : 7,
	'scotland' : 30,
	'south africa' : 3,
	'sri lanka' : 8,
	'west indies' : 4,
	'zimbabwe' : 9
	}
	formats = {
	'tests' : 1,
	'odis' : 2,
	't20is' : 3,
	'test' : 1,
	'odi' : 2,
	't20i' : 3,
	}
	
	base_url='http://stats.espncricinfo.com/stats/engine/player/'
	url = base_url+ str(playerId) + "?"+ 'class='+str(formats[format]) +';opposition='+str(country_codes[oppositionTeamName.lower()])+";template=results;type=allround"
	soup = returnSoup(url)

	for table in soup.find_all(class_="engineTable"):
		if table.caption:
			if table.caption.string=='Career averages':
				for tableRow in table.find_all(class_="data1"):
					for tableData in tableRow.find_all("td"):
						#if ((not (tableData.has_attr("class") or tableData.has_attr("style"))) or tableData.get('class')==["padAst"] or tableData.get('class')==["padDp2"]):
						if (not (tableData.get("class")==["left"] or tableData.has_attr("style"))):
							if tableData.string:
								returnString=returnString+tableData.string+"|"
							else:
								returnString=returnString+" |"
					returnString=returnString+" |"
	if returnString[-2:]==" |":
		returnString=returnString[:-2]
	return returnString
Ejemplo n.º 3
0
def getLiveScoreText(iFrameLink):
    returnText = ["", "", ""]
    returnText[1] = "***\n\n|Team|Score|\n|:---|:---|"
    soup = returnSoup(iFrameLink)
    for Table in soup.find_all(class_="desktopPanelContent"):
        returnText[1] = returnText[1] + HTMLTableToPythonTable(
            Table)[1] + "\n\n"
        returnText[2] = returnText[2] + HTMLTableToPythonTable(Table)[2]
    index = returnText[1].find("|Batsmen|R|B|4s|6s|") + len(
        "|Batsmen|R|B|4s|6s|")
    finalReturnText = returnText[
        1][:index] + "\n|:---|:---|:---|:---|:---|" + returnText[1][index:]
    finalReturnText = finalReturnText + returnText[2]
    finalReturnText = finalReturnText + "***"
    return finalReturnText
Ejemplo n.º 4
0
def readInternationalFixtures(myurl, ciResults):
    """
    The purpose of this function is to extract data from espncricinfo about the 
    current and future matches and store that result in a dictionary. 
    """
    soup = returnSoup(myurl)

    matchDateId = None
    matchRowId = None

    rowType = {'id': 'date', 'class': 'match'}

    # Obtain only the results which are rows in the table
    allRows = soup.find_all('tr')

    i = 0
    for row in allRows:
        if 'id' in row.attrs:
            rowType = "date"
        elif 'class' in row.attrs:
            rowType = "match"
        else:
            rowType = ""

        if rowType == "date":
            if 'id' in row.attrs:
                (matchDateId, matchDate) = getText(row, 'id')
                matchRowId = None

        elif rowType == "match":
            if 'head_id' in row.attrs and 'class' in row.attrs and str(
                    row['class'][0]) == "ciResults":
                if row['head_id'] == matchDateId:
                    columns = row.find_all('td')
                    i += 1
                    ciResults[i] = {}
                    ciResults[i]['Day'] = matchDate[4:]
                    formatColumn(columns, ciResults, i)

            for link in row.find_all('a'):
                ciResults[i][
                    'Link'] = 'http://www.espncricinfo.com' + link.get('href')

    return ciResults
Ejemplo n.º 5
0
def readInternationalFixtures( myurl, ciResults):
    """
    The purpose of this function is to extract data from espncricinfo about the 
    current and future matches and store that result in a dictionary. 
    """
    soup = returnSoup( myurl )

    matchDateId = None
    matchRowId = None

    rowType = {'id':'date',
               'class':'match'}

    # Obtain only the results which are rows in the table
    allRows = soup.find_all('tr')

    i=0
    for row in allRows:
        if 'id' in row.attrs:
            rowType = "date"
        elif 'class' in row.attrs:
            rowType = "match"
        else:
            rowType = ""

        if rowType == "date":
            if 'id' in row.attrs:
                (matchDateId, matchDate) = getText(row, 'id')
                matchRowId = None

        elif rowType == "match":
            if 'head_id' in row.attrs and 'class' in row.attrs and str(row['class'][0]) =="ciResults":
                if row['head_id'] == matchDateId:
                    columns = row.find_all('td')
                    i+=1
                    ciResults[i]={}
                    ciResults[i]['Day']=matchDate[4:]
                    formatColumn (columns,ciResults,i)
                    
            for link in row.find_all('a'):
                ciResults[i]['Link']='http://www.espncricinfo.com'+link.get('href')

    return ciResults