Assistance with AutoIt code from sofascore (tennis)

Discussion regarding the spreadsheet functionality of Bet Angel.
Post Reply
zippus
Posts: 181
Joined: Thu Jun 13, 2019 3:19 pm

One really for Stu aka Sniffer.

I'd really appreciate your help solving a couple of issues with the AutoIt code please. I've searched online to no avail and have attempted to use your football scripts to extract tennis data from Sofascore. The issues:

1) The csv file for sets 2-5 shows blanks but I'd like them to show zeroes.

Attempted fix. No error but does nothing:

If Json_Get($object, '.events.homeScore.period2') = "" Then
FileWrite($object, "0")

EndIf

2) The tennis surnames often contain characters that aren't recognised in our alphabet.

Attempted fix. No error but does nothing:

Func _StringReplaceAccent($sString)
Local $exp, $rep
Local $Pattern[29][2] = [ _
["[ÀÁÂÃÅÆ]", "A"], ["[àáâãåa]", "a"], ["Ä", "Ae"], ["[æä]", "ae"], ["á", "a"], ["ú", "u"], ["é", "e"], , ["Ã", "i"] _
["Þ", "B"], ["þ", "b"], _
["ÇC", "C"], ["[çcc]", "c"], ["Å¡iÄ", "sic"], _
["[ÈÉÊË]", "E"], ["[èéêë]", "e"], _
["[ÌÍÎÏ]", "I"], ["[ìíîï]", "i"], _
["Ñ", "N"], ["ñ", "n"], _
["[ÒÓÔÕÖØ]", "O"], ["[ðòóôõöø]", "o"], _
["r", "r"], _
["[ŠS]", "S"], ["[š]", "s"], _
["ß", "Ss"], _
["?", "T"], _
[",", ""], _
["[ÙÚÛ]", "U"], ["[ùúû]", "u"], ["Ü", "Ue"], ["ü", "ue"], _
["Ý", "Y"], ["[ýýÿ]", "y"], _
["Ž", "Z"], ["ž", "z"]]


I've listed the full code below, so any assistance would be greatly appreciated.

Thanks very much!


Code: Select all

#include <Inet.au3>
#include <json.au3>
#include <Array.au3>
#include <String.au3>
#include <File.au3>

$TitleString = "Team|Tennis"

;File to connect Guardian to. Will save in same location as script
$File = "tennis.csv"

While 1

	$URL = "https://api.sofascore.com/api/v1/sport/tennis/events/live"
	$data = _INetGetSource($URL)
	$object = json_decode($data)

	Local $Count = Json_Get($object, '.events')

	FileDelete($File)
	FileOpen($File)

	$z = 0

	For $i = 0 To UBound($Count) - 1

		;Writing "1" to first line of the CSV. Required by Guardian
		If $z = 0 Then
			FileWriteLine($File, "1")
		EndIf
		$z = 1

If Json_Get($object, '.events.homeScore.period2') = "" Then
		 FileWrite($object, "0")

		EndIf



		$HomeString = "*,*," & "*" & Json_Get($object, '.events' & '[' & $i & '].homeTeam.shortName') & "*,*,"
		$AwayString = "*,*," & "*" & Json_Get($object, '.events' & '[' & $i & '].awayTeam.shortName') & "*,*,"

		$HomeString = $HomeString & "SS,Set1," & Json_Get($object, '.events' & '[' & $i & '].homeScore.period1') &"," & "SS,Set2," & Json_Get($object, '.events' & '[' & $i & '].homeScore.period2') &"," & "SS,Set3," & Json_Get($object, '.events' & '[' & $i & '].homeScore.period3') &"," & "SS,Set4," & Json_Get($object, '.events' & '[' & $i & '].homeScore.period4') &"," & "SS,Set5," & Json_Get($object, '.events' & '[' & $i & '].homeScore.period5') &"," & "SS,Point," & Json_Get($object, '.events' & '[' & $i & '].homeScore.point') &"," & "SS,Gender," & Json_Get($object, '.events' & '[' & $i & '].homeTeam.gender')
		$AwayString = $AwayString & "SS,Set1," & Json_Get($object, '.events' & '[' & $i & '].awayScore.period1') &"," & "SS,Set2," & Json_Get($object, '.events' & '[' & $i & '].awayScore.period2') &"," & "SS,Set3," & Json_Get($object, '.events' & '[' & $i & '].awayScore.period3') &"," & "SS,Set4," & Json_Get($object, '.events' & '[' & $i & '].awayScore.period4') &"," & "SS,Set5," & Json_Get($object, '.events' & '[' & $i & '].awayScore.period5') &"," & "SS,Point," & Json_Get($object, '.events' & '[' & $i & '].awayScore.point') &"," & "SS,Gender," & Json_Get($object, '.events' & '[' & $i & '].awayTeam.gender')








	  #include <MsgBoxConstants.au3>




		;MsgBox($MB_SYSTEMMODAL, "Score", $HomeString & @CRLF & $AwayString)
		FileWriteLine($File,$HomeString)
		FileWriteLine($File,$AwayString)



	Next

	FileClose($File)

	;Wait time between score refresh in milliseconds
	;#######DO NOT SET SHORTER THAN 10S AS YOUR IP MAY BE BLOCKED#####

	Sleep(15000) ;15 seconds


 WEND

Func _StringReplaceAccent($sString)
	Local $exp, $rep
	Local $Pattern[29][2] = [ _
			["[ÀÁÂÃÅÆ]", "A"], ["[àáâãåa]", "a"], ["Ä", "Ae"], ["[æä]", "ae"], ["á", "a"], ["ú", "u"], ["é", "e"], , ["Ã", "i"] _
			["Þ", "B"], ["þ", "b"], _
			["ÇC", "C"], ["[çcc]", "c"], ["Å¡iÄ", "sic"], _
			["[ÈÉÊË]", "E"], ["[èéêë]", "e"], _
			["[ÌÍÎÏ]", "I"], ["[ìíîï]", "i"], _
			["Ñ", "N"], ["ñ", "n"], _
			["[ÒÓÔÕÖØ]", "O"], ["[ðòóôõöø]", "o"], _
			["r", "r"], _
			["[ŠS]", "S"], ["[š]", "s"], _
			["ß", "Ss"], _
			["?", "T"], _
			[",", ""], _
			["[ÙÚÛ]", "U"], ["[ùúû]", "u"], ["Ü", "Ue"], ["ü", "ue"], _
			["Ý", "Y"], ["[ýýÿ]", "y"], _
			["Ž", "Z"], ["ž", "z"]]

	For $i = 0 To (UBound($Pattern) - 1)
		$exp = $Pattern[$i][0]
		If $exp = "" Then ContinueLoop
		$rep = $Pattern[$i][1]

		$sString = StringRegExpReplace($sString, $exp, $rep)
		If @error == 0 And @extended > 0 Then
			;ConsoleWrite($sString & @LF & "--> " & $exp & @LF)
		EndIf
	Next

	Return $sString
EndFunc   ;==>_StringReplaceAccent
User avatar
Euler
Posts: 24803
Joined: Wed Nov 10, 2010 1:39 pm
Location: Bet Angel HQ

You know you can already get live scores through Bet Angel?
zippus
Posts: 181
Joined: Thu Jun 13, 2019 3:19 pm

Euler wrote:
Sat Mar 19, 2022 10:52 am
You know you can already get live scores through Bet Angel?
Thanks Peter. It's really for the tournaments where the Betfair feed isn't available e.g. the Australian Open.
User avatar
Euler
Posts: 24803
Joined: Wed Nov 10, 2010 1:39 pm
Location: Bet Angel HQ

OK, just wanted to check. Just incase.
sniffer66
Posts: 1679
Joined: Thu May 02, 2019 8:37 am

Hi Zippus

Sorry I've been quiet, had a few non trading issues to deal with

I've been reworking some of the footy code for tennis, and adding in the name matching changes I've made on the footy to my old tennis scripts

You after something like this ? If you want to add in scores, the framework is all there to return the required JSON.
At the moment I'm just looking at the data for the match, but very possible to get set by set to compare differences

Code: Select all

29/03/2022 11:14:52: [G_Auto 1] :  Store Value for L Boskovic: 1stServeIn% = 74
29/03/2022 11:14:52: [G_Auto 1] :  Store Value for L Boskovic: 1stServePointsWon% = 71
29/03/2022 11:14:52: [G_Auto 1] :  Store Value for L Boskovic: 2ndServeIn% = 67
29/03/2022 11:14:52: [G_Auto 1] :  Store Value for L Boskovic: 2ndServePointsWon% = 33
29/03/2022 11:14:52: [G_Auto 1] :  Store Value for L Boskovic: OppReceivePointsWon = 18
29/03/2022 11:14:52: [G_Auto 1] :  Store Value for L Boskovic: BPAgainst = 3
29/03/2022 11:14:52: [G_Auto 1] :  Store Value for L Boskovic: BPSaved% = 0
29/03/2022 11:14:52: [G_Auto 1] :  Store Value for J Avdeeva: 1stServeIn% = 60
29/03/2022 11:14:52: [G_Auto 1] :  Store Value for J Avdeeva: 1stServePointsWon% = 62
29/03/2022 11:14:52: [G_Auto 1] :  Store Value for J Avdeeva: 2ndServeIn% = 87
29/03/2022 11:14:52: [G_Auto 1] :  Store Value for J Avdeeva: 2ndServePointsWon% = 0
29/03/2022 11:14:52: [G_Auto 1] :  Store Value for J Avdeeva: OppReceivePointsWon = 25
29/03/2022 11:14:52: [G_Auto 1] :  Store Value for J Avdeeva: BPAgainst = 7
29/03/2022 11:14:52: [G_Auto 1] :  Store Value for J Avdeeva: BPSaved% = 57
Last edited by sniffer66 on Tue Mar 29, 2022 1:45 pm, edited 1 time in total.
sniffer66
Posts: 1679
Joined: Thu May 02, 2019 8:37 am

I've also played around with scores in the past - when BF lost the license to send WTA scores. However, you can't refresh fast enough to get in game point scores fast enough to trade with. Games and set scores is do-able though.
zippus
Posts: 181
Joined: Thu Jun 13, 2019 3:19 pm

Thanks Sniffer! Appreciate the assistance. I'll take a look at what you've sent and will see if this fixes things.
Post Reply

Return to “Bet Angel - Spreadsheet / Excel chat”