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