Ok, had to get a little creative trying to prevent double matches (2 teams playing as City etc)
I've added in a function that will split the entire team name, delimiting by spaces, and then find the first of those split strings with more than 3 characters. It then checks all previous name matches downloaded on that cycle to see if that string exists for another team (City, United etc) and moves on to the next string > 3 chars if another match is found. It will then wildcard that sub string in the CSV. It will also specify the row number in the CSV (1 for Home Team, 2 for Away)
If it cant find any unique string of more than 3 characters it will return a selection name of "NotFound" and not match any selection. I think it better to not have a score returned at all than to return a score for another team. You'll need to cater for a non entry in your baf
Anything less than a 4 character string will cause too many matches IMO
I've also addedd in a function that will strip out most, if not all special characters - accents, circumflex etc
That's about as much as I can do. I think you'll be pretty unlucky to have an incorrect match, in the same row but I could be wrong. Test and let me know
Stu
Tested fine on Mongolia v Japan
30/03/2021 12:57:16: [G_Auto 1] : Store Value for Mongolia: Score = 0
30/03/2021 12:57:16: [G_Auto 1] : Store Value for Japan: Score = 7
30/03/2021 12:57:22: [G_Auto 1] : Store Value for Mongolia: Score = 0
30/03/2021 12:57:22: [G_Auto 1] : Store Value for Japan: Score = 7
30/03/2021 12:57:27: [G_Auto 1] : Store Value for Mongolia: Score = 0
30/03/2021 12:57:27: [G_Auto 1] : Store Value for Japan: Score = 7
30/03/2021 12:57:32: [G_Auto 1] : Store Value for Mongolia: Score = 0
30/03/2021 12:57:32: [G_Auto 1] : Store Value for Japan: Score = 7
30/03/2021 12:57:37: [G_Auto 1] : Store Value for Mongolia: Score = 0
30/03/2021 12:57:37: [G_Auto 1] : Store Value for Japan: Score = 7
30/03/2021 12:57:43: [G_Auto 1] : Store Value for Mongolia: Score = 0
30/03/2021 12:57:43: [G_Auto 1] : Store Value for Japan: Score = 7
30/03/2021 12:57:45: Guardian has detected that the market is suspended
Current CSV looks like this:
* * *Mongolia* 1 S Score 0
* * *Japan* 2 S Score 8
* * *Maziya* 1 S Score 0
* * *United* 2 S Score 0
* * *Nedlands* 1 S Score 1
* * *Gosnells* 2 S Score 4
* * *Bristol* 1 S Score 0
* * *Millwall* 2 S Score 0
* * *Velsao* 1 S Score 1
* * *Churchill* 2 S Score 2
* * *Eves* 1 S Score 1
* * *Hindustan* 2 S Score 1
* * *Sudeva* 1 S Score 2
* * *Rangers* 2 S Score 1
* * *Arema* 1 S Score 1
* * *PSIS* 2 S Score 0
* * *Maccabi* 1 S Score 0
* * *Bnei* 2 S Score 0
* * *Sport* 1 S Score 0
* * *Hapoel* 2 S Score 1
* * *Ironi* 1 S Score 0
* * *Pardes* 2 S Score 0
* * *Hakoach* 1 S Score 0
* * *Marmorek* 2 S Score 2
* * *Shurtan* 1 S Score 0
* * *Buxoro* 2 S Score 0
* * *Becamex* 1 S Score 0
* * *NotFound* 2 S Score 1
Code: Select all
#include <Inet.au3>
#include <json.au3>
#include <Array.au3>
#include <String.au3>
#include <File.au3>
$TitleString = "Team|Score"
;File to connect Guardian to. Will save in same location as script
$File = "score.csv"
While 1
$URL = "https://api.sofascore.com/api/v1/sport/football/events/live"
$data = _INetGetSource($URL)
$object = json_decode($data)
Local $Count = Json_Get($object, '.events')
FileDelete($File)
FileOpen($File)
$z = 0
Local $NameArray[1]
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
$HomeTeam = _StringReplaceAccent(Strip(Json_Get($object, '.events' & '[' & $i & '].homeTeam.name')))
$AwayTeam = _StringReplaceAccent(Strip(Json_Get($object, '.events' & '[' & $i & '].awayTeam.name')))
$HomeString = "*,*," & "*" & $HomeTeam & "*,1,"
$AwayString = "*,*," & "*" & $AwayTeam & "*,2,"
$HomeString = $HomeString & "S,Score," & Json_Get($object, '.events' & '[' & $i & '].homeScore.current')
$AwayString = $AwayString & "S,Score," & Json_Get($object, '.events' & '[' & $i & '].awayScore.current')
$URL = "https://api.sofascore.com/api/v1/event/" & Json_Get($object, '.events' & '[' & $i & '].id') & "/statistics"
;MsgBox("", "", $URL)
$data1 = _INetGetSource($URL)
If $data1 <> "" Then
;Json_Dump($data1)
;MsgBox("", "", $data1)
EndIf
;MsgBox($MB_SYSTEMMODAL, "Score", $HomeString & @CRLF & $AwayString)
FileWriteLine($File, $HomeString)
FileWriteLine($File, $AwayString)
_ArrayAdd($NameArray, $HomeTeam)
_ArrayAdd($NameArray, $AwayTeam)
;_ArrayDisplay($NameArray)
Next
FileClose($File)
;Wait time between score refresh in milliseconds
;#######DO NOT SET SHORTER THAN 10S AS YOUR IP MAY BE BLOCKED#####
Sleep(30000) ;30 seconds
WEnd
Func Strip($Param)
$f = "NotFound"
$e = StringSplit($Param, " ")
;_ArrayDisplay($e)
For $z = 1 To UBound($e) - 1
_ArraySearch($NameArray, $e[$z])
If @error Then
If StringLen($e[$z]) > 3 Then
$f = $e[$z]
ExitLoop
EndIf
EndIf
Next
;MsgBox($MB_SYSTEMMODAL, "Result", $f )
Return $f
EndFunc ;==>Strip
Func _StringReplaceAccent($sString)
Local $exp, $rep
Local $Pattern[29][2] = [ _
["[ÀÁÂÃÅÆ]", "A"], ["[àáâãåą]", "a"], ["Ä", "Ae"], ["[æä]", "ae"], _
["Þ", "B"], ["þ", "b"], _
["ÇĆ", "C"], ["[çćč]", "c"], _
["[ÈÉÊË]", "E"], ["[èéêë]", "e"], _
["[ÌÍÎÏ]", "I"], ["[ìíîï]", "i"], _
["Ñ", "N"], ["ñ", "n"], _
["[ÒÓÔÕÖØ]", "O"], ["[ðòóôõöø]", "o"], _
["ř", "r"], _
["[ŠŚ]", "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