Football scores to Guardian programatically - Script & Sample BAF

Football, Soccer - whatever you call it. It is the beautiful game.
sniffer66
Posts: 1666
Joined: Thu May 02, 2019 8:37 am

Wonkymuffin wrote:
Mon Mar 08, 2021 9:53 am
The work you have done so far with the scores is working brilliantly for me. My comment was in relation to the in-play stats from Sofascore as you had previously mentioned that it would be easy (well for you anyway!) to add these in to the csv. Thanks again.

I'm afraid I've had to time lately. In the middle of moving house so all over the place

It's worth doing some reading on the Auto-It forum - some good examples in those threads I linked. Definitely preferable to pick up the skills yourself then you can pull data down for any sport you like

Try using the existing script and the Json_Dump() function I've mentioned previously and that will give you an idea of how the json notation works, then it's just a case of adding additional lines to pull the values you are after.
As a hint, the stats are on an additional URL, which you can create from the JSON containing the current scores. Put a link/Json_Get to that in the existing score loop and you can then grab all the stats you like

Starter for 10:

$URL = "https://api.sofascore.com/api/v1/event/" & Json_Get($object, '.events' & '[' & $i & '].id') & "/statistics"
User avatar
Euler
Posts: 24700
Joined: Wed Nov 10, 2010 1:39 pm
Location: Bet Angel HQ

You've got me interested in this from a broader perspective. So thanks again, for taking the time to share it.
sniffer66
Posts: 1666
Joined: Thu May 02, 2019 8:37 am

Euler wrote:
Mon Mar 08, 2021 1:14 pm
You've got me interested in this from a broader perspective. So thanks again, for taking the time to share it.
No problem Peter. I was doing this via Excel previously but the new CSV import function simplifies it hugely (and saves a lot in CPU overhead)
Lovely when you can get up to date data like this into Guardian

08/03/2021 13:08:41: [G_Auto 1] : Store Value for Alex Molcan: 1stServeIn% = 61
08/03/2021 13:08:41: [G_Auto 1] : Store Value for Alex Molcan: 1stServePoints% = 91
08/03/2021 13:08:41: [G_Auto 1] : Store Value for Alex Molcan: 2ndServePoints% = 86
08/03/2021 13:08:41: [G_Auto 1] : Store Value for Alex Molcan: OppPointsCount = 2
08/03/2021 13:08:41: [G_Auto 1] : Store Value for Alex Molcan: BPAgainstCount = 0
08/03/2021 13:08:41: [G_Auto 1] : Store Value for Alex Molcan: ServeBrokenNo = 0
08/03/2021 13:10:25: [G_Auto 1] : Store Value for Ernests Gulbis: 1stServeIn% = 55
08/03/2021 13:10:25: [G_Auto 1] : Store Value for Ernests Gulbis: 1stServePoints% = 75
08/03/2021 13:10:25: [G_Auto 1] : Store Value for Ernests Gulbis: 2ndServePoints% = 23
08/03/2021 13:10:25: [G_Auto 1] : Store Value for Ernests Gulbis: OppPointsCount = 14
08/03/2021 13:10:25: [G_Auto 1] : Store Value for Ernests Gulbis: BPAgainstCount = 8
08/03/2021 13:10:25: [G_Auto 1] : Store Value for Ernests Gulbis: ServeBrokenNo = 2
08/03/2021 13:10:25: [G_Auto 1] : Store Value for market: GameCount = 8 + 1 = 9
08/03/2021 13:13:56: [G_Auto 1] : Store Value for Alex Molcan: 1stServeIn% = 70
08/03/2021 13:13:56: [G_Auto 1] : Store Value for Alex Molcan: 1stServePoints% = 88
08/03/2021 13:13:56: [G_Auto 1] : Store Value for Alex Molcan: 2ndServePoints% = 86
08/03/2021 13:13:56: [G_Auto 1] : Store Value for Alex Molcan: OppPointsCount = 3
08/03/2021 13:13:56: [G_Auto 1] : Store Value for Alex Molcan: BPAgainstCount = 0
08/03/2021 13:13:56: [G_Auto 1] : Store Value for Alex Molcan: ServeBrokenNo = 0
08/03/2021 13:13:56: [G_Auto 1] : Store Value for market: GameCount = 9 + 1 = 10
User avatar
jimibt
Posts: 3641
Joined: Mon Nov 30, 2015 6:42 pm
Location: Narnia

sniffer66 wrote:
Mon Mar 08, 2021 1:17 pm
Euler wrote:
Mon Mar 08, 2021 1:14 pm
You've got me interested in this from a broader perspective. So thanks again, for taking the time to share it.
No problem Peter. I was doing this via Excel previously but the new CSV import function simplifies it hugely (and saves a lot in CPU overhead)
Lovely when you can get up to date data like this into Guardian

08/03/2021 13:08:41: [G_Auto 1] : Store Value for Alex Molcan: 1stServeIn% = 61
08/03/2021 13:08:41: [G_Auto 1] : Store Value for Alex Molcan: 1stServePoints% = 91
08/03/2021 13:08:41: [G_Auto 1] : Store Value for Alex Molcan: 2ndServePoints% = 86
08/03/2021 13:08:41: [G_Auto 1] : Store Value for Alex Molcan: OppPointsCount = 2
08/03/2021 13:08:41: [G_Auto 1] : Store Value for Alex Molcan: BPAgainstCount = 0
08/03/2021 13:08:41: [G_Auto 1] : Store Value for Alex Molcan: ServeBrokenNo = 0
08/03/2021 13:10:25: [G_Auto 1] : Store Value for Ernests Gulbis: 1stServeIn% = 55
08/03/2021 13:10:25: [G_Auto 1] : Store Value for Ernests Gulbis: 1stServePoints% = 75
08/03/2021 13:10:25: [G_Auto 1] : Store Value for Ernests Gulbis: 2ndServePoints% = 23
08/03/2021 13:10:25: [G_Auto 1] : Store Value for Ernests Gulbis: OppPointsCount = 14
08/03/2021 13:10:25: [G_Auto 1] : Store Value for Ernests Gulbis: BPAgainstCount = 8
08/03/2021 13:10:25: [G_Auto 1] : Store Value for Ernests Gulbis: ServeBrokenNo = 2
08/03/2021 13:10:25: [G_Auto 1] : Store Value for market: GameCount = 8 + 1 = 9
08/03/2021 13:13:56: [G_Auto 1] : Store Value for Alex Molcan: 1stServeIn% = 70
08/03/2021 13:13:56: [G_Auto 1] : Store Value for Alex Molcan: 1stServePoints% = 88
08/03/2021 13:13:56: [G_Auto 1] : Store Value for Alex Molcan: 2ndServePoints% = 86
08/03/2021 13:13:56: [G_Auto 1] : Store Value for Alex Molcan: OppPointsCount = 3
08/03/2021 13:13:56: [G_Auto 1] : Store Value for Alex Molcan: BPAgainstCount = 0
08/03/2021 13:13:56: [G_Auto 1] : Store Value for Alex Molcan: ServeBrokenNo = 0
08/03/2021 13:13:56: [G_Auto 1] : Store Value for market: GameCount = 9 + 1 = 10
will be even lovlier when the SV-CSV functionality is updated to allow MarketId and SelectionId to be passed in, rather than coercing and mapping variations of name etc..!! :mrgreen:

viewtopic.php?f=20&t=23204
petermikael
Posts: 4
Joined: Fri Jun 19, 2020 9:40 am

sniffer66 wrote:
Mon Mar 08, 2021 8:39 am
petermikael wrote:
Sun Mar 07, 2021 11:21 am
Trying to download scores but no score.csv is to find on my computer. This feature is great so help is much appreciated. I have let the script run for several minutes before i terminated the process. I go to tools->Go and the console looks like this >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Program Files (x86)\AutoIt3\Examples\Football.au3" The score.csv should be saved down to the same folder as Football.au3 if i understand it correct?
To be honest, I've not used this since I created it as I don't trade football on auto in BA - just thought it would be useful

I've just tested it though and ran fine for me - CSV file saves to same folder location as the script

Returned

1
* * *Central Coast Mariners* * S Score 1
* * *Macarthur FC* * S Score 0
* * *Abeldos United* * S Score 0
* * *Ab ovo* * S Score 0
* * *Bangalore Dream United FC* * S Score 0
* * *Income Tax SC* * S Score 0

Did you download the addititonal UDF's mentioned previously in the thread, and are you seeing any errors in the Scite Console ?
Did a restart on my computer and then it worked :D Thanks for the reply
MattP
Posts: 31
Joined: Mon Feb 08, 2021 9:34 pm

With this I guess most people will want to use it to enter (or exit) a trade following a goal.

It's likely the market will be suspended at the time the goal updates do how does BA manage that?

It looks like a great addition though!
sniffer66
Posts: 1666
Joined: Thu May 02, 2019 8:37 am

I would suggest an Unsuspended Time condition. Wait a while for the market to unsuspend and then time to settle.
Wonkymuffin
Posts: 6
Joined: Wed Nov 09, 2016 8:46 am

sniffer66 wrote:
Mon Mar 08, 2021 11:48 am
Wonkymuffin wrote:
Mon Mar 08, 2021 9:53 am
The work you have done so far with the scores is working brilliantly for me. My comment was in relation to the in-play stats from Sofascore as you had previously mentioned that it would be easy (well for you anyway!) to add these in to the csv. Thanks again.

I'm afraid I've had to time lately. In the middle of moving house so all over the place

It's worth doing some reading on the Auto-It forum - some good examples in those threads I linked. Definitely preferable to pick up the skills yourself then you can pull data down for any sport you like

Try using the existing script and the Json_Dump() function I've mentioned previously and that will give you an idea of how the json notation works, then it's just a case of adding additional lines to pull the values you are after.
As a hint, the stats are on an additional URL, which you can create from the JSON containing the current scores. Put a link/Json_Get to that in the existing score loop and you can then grab all the stats you like

Starter for 10:

$URL = "https://api.sofascore.com/api/v1/event/" & Json_Get($object, '.events' & '[' & $i & '].id') & "/statistics"
Thank you for the additional help. I have carried out these steps and extracted the additional info. However, there are no useful in-play stats there so I am guessing that these are 'hidden' away under a different URL. I might be wrong but gaining additional AutoIt knowledge will not get me to where I want to be so think I'll have to put this on hold for now.
sniffer66
Posts: 1666
Joined: Thu May 02, 2019 8:37 am

Wonkymuffin wrote:
Thu Mar 11, 2021 10:48 pm
sniffer66 wrote:
Mon Mar 08, 2021 11:48 am
Wonkymuffin wrote:
Mon Mar 08, 2021 9:53 am
The work you have done so far with the scores is working brilliantly for me. My comment was in relation to the in-play stats from Sofascore as you had previously mentioned that it would be easy (well for you anyway!) to add these in to the csv. Thanks again.

I'm afraid I've had to time lately. In the middle of moving house so all over the place

It's worth doing some reading on the Auto-It forum - some good examples in those threads I linked. Definitely preferable to pick up the skills yourself then you can pull data down for any sport you like

Try using the existing script and the Json_Dump() function I've mentioned previously and that will give you an idea of how the json notation works, then it's just a case of adding additional lines to pull the values you are after.
As a hint, the stats are on an additional URL, which you can create from the JSON containing the current scores. Put a link/Json_Get to that in the existing score loop and you can then grab all the stats you like

Starter for 10:

$URL = "https://api.sofascore.com/api/v1/event/" & Json_Get($object, '.events' & '[' & $i & '].id') & "/statistics"
Thank you for the additional help. I have carried out these steps and extracted the additional info. However, there are no useful in-play stats there so I am guessing that these are 'hidden' away under a different URL. I might be wrong but gaining additional AutoIt knowledge will not get me to where I want to be so think I'll have to put this on hold for now.
I actually gave you the "hidden" URL in the starter for 10

Try running this, then check the Scite Console (lower pane). I think you'll agree its worth learning a few skills after that. TBH, all you need to do at that point is replicate what I've done already, but after the stats URL is retrieved. More inplay data than you can shake a stick at ;)

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

	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


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

		$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)


	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

Wonkymuffin
Posts: 6
Joined: Wed Nov 09, 2016 8:46 am

I used the URL provided but did not add "$data1 = _INetGetSource($URL)" so I guess this is why I did not get the required data. So in that case, yes, more knowledge would have been useful. ;)
The required stats are now available to me so I will work on getting a suitable csv and will post back here when I've achieved that. Thank you again for all of your help.
sniffer66
Posts: 1666
Joined: Thu May 02, 2019 8:37 am

Wonkymuffin wrote:
Fri Mar 12, 2021 12:00 pm
I used the URL provided but did not add "$data1 = _INetGetSource($URL)" so I guess this is why I did not get the required data. So in that case, yes, more knowledge would have been useful. ;)
The required stats are now available to me so I will work on getting a suitable csv and will post back here when I've achieved that. Thank you again for all of your help.
Yes, you have to retrieve the data from the new stats URL before you can parse it.

Have fun with the stats 👍
petermikael
Posts: 4
Joined: Fri Jun 19, 2020 9:40 am

I am working on a solution to compare the teamnames with betfair teamnames, if i am correct theres no way to match them if they are not spelled exactly the same. Is there a way to download teamnames from betfair or maybe someone already have them and could share. Please correct me if i am completely wrong, maybe someone already solved this but i missed it. It would be almost magic if it could be done, it opens up a lot of possibilities. Tried other ways to get the correct score ( comparing odds by examples from Dallas) but for me it is not working as good as it should.
sniffer66
Posts: 1666
Joined: Thu May 02, 2019 8:37 am

petermikael wrote:
Tue Mar 23, 2021 2:38 pm
I am working on a solution to compare the teamnames with betfair teamnames, if i am correct theres no way to match them if they are not spelled exactly the same. Is there a way to download teamnames from betfair or maybe someone already have them and could share. Please correct me if i am completely wrong, maybe someone already solved this but i missed it. It would be almost magic if it could be done, it opens up a lot of possibilities. Tried other ways to get the correct score ( comparing odds by examples from Dallas) but for me it is not working as good as it should.

What I do with the tennis is just match on the surname by doing a string strip in the script, then I only match the first 10 letters or so. That removes the issue where BF has "Leeds" and the API returns "Leeds United" for example. Then I wildcard the match in BA so it will match the Selection if Leeds is anywhere in the BF name. That should solve most, if not all matching issues. if you aren't up to scripting that let me know and I'll add in the function I'm using to the existing code when I get a sec - taking any string before the first space as the text to match on

I also have a function to remove most special characters - accents, circumflex etc, which will also help

I only posted the original as an example so never got around to testing it fully for selection matching.
Wonkymuffin
Posts: 6
Joined: Wed Nov 09, 2016 8:46 am

I too have encountered a couple of problems with this and have not had the time to try and resolve them, but will state them here so that others are aware.

1. Yes, the team name matching has been a problem and the ideas listed by sniffer66 will be useful and a step in the right direction. I have been using the Sofascore shortname which offers better matching than the long name but does give errors which are either due to strange characters in the name (UK matches have all been okay) or due to similar team names - Note for sniffer66 - using just the first part of the team name, up to the first space, will be of benefit but will not always work (which means that personally I wouldn't rely on it). A for instance is Bristol which is used in four different team names. Bristol City, Rovers, City U23, City WFC.
2. Whilst there are many Sofascore matches with copious statistics there are more without, so for me personally I will miss out on many opportunities. Not alot can be done about that and if you are only interested in the score then it will not affect you.
sniffer66
Posts: 1666
Joined: Thu May 02, 2019 8:37 am

Wonkymuffin wrote:
Tue Mar 23, 2021 5:12 pm
I too have encountered a couple of problems with this and have not had the time to try and resolve them, but will state them here so that others are aware.

1. Yes, the team name matching has been a problem and the ideas listed by sniffer66 will be useful and a step in the right direction. I have been using the Sofascore shortname which offers better matching than the long name but does give errors which are either due to strange characters in the name (UK matches have all been okay) or due to similar team names - Note for sniffer66 - using just the first part of the team name, up to the first space, will be of benefit but will not always work (which means that personally I wouldn't rely on it). A for instance is Bristol which is used in four different team names. Bristol City, Rovers, City U23, City WFC.
2. Whilst there are many Sofascore matches with copious statistics there are more without, so for me personally I will miss out on many opportunities. Not alot can be done about that and if you are only interested in the score then it will not affect you.

Good points. The way to use a short string is to actually check that both teams match the short name. So even if you have Bristol as home team, then the other team has to match as well before the data is used in the automation.
That might be an issue in a derby but again you could pull 2 short strings (pre and post space) and match on both... United & City for instance
Post Reply

Return to “Football trading”