Last active
May 10, 2025 06:49
-
-
Save hansogj/6707317d5726e7c70778dafa6dcc9de3 to your computer and use it in GitHub Desktop.
Henter spillerstatistikk fra FIKS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const squadRefefer = (SquadId) => `https://fiks.fotball.no/FiksWeb/Team/View/${SquadId}` | |
const matchRefefer = (MatchId) => `https://fiks.fotball.no/FiksWeb/MatchReport/View/${MatchId}` | |
const config = (referer) => ({ | |
"headers": { | |
"accept": "*/*", | |
"accept-language": "en-NO,en;q=0.9,nb-NO;q=0.8,nb;q=0.7,en-US;q=0.6,no;q=0.5", | |
"content-type": "application/json", | |
"request-context": "appId=cid-v1:ec51181e-6f14-4136-83be-4bcfeeee0d97", | |
"request-id": "|nKclB.yx39I", | |
"sec-ch-ua": "\"Google Chrome\";v=\"135\", \"Not-A.Brand\";v=\"8\", \"Chromium\";v=\"135\"", | |
"sec-ch-ua-mobile": "?0", | |
"sec-ch-ua-platform": "\"Windows\"", | |
"sec-fetch-dest": "empty", | |
"sec-fetch-mode": "cors", | |
"sec-fetch-site": "same-origin" | |
}, | |
"referrer": referer, | |
"referrerPolicy": "strict-origin-when-cross-origin", | |
"body": null, | |
"method": "GET", | |
"mode": "cors", | |
"credentials": "include" | |
}) | |
const extractSquad = (data, SquadId ) => { | |
const squad = data.HomeTeamId === SquadId ? data.HomeTeamPlayers : data.AwayTeamPlayers; | |
return squad.map(({FullName}) => FullName ); | |
} | |
const getMatchSquad = async (MatchId, SquadId) => | |
await getMatch(MatchId).then( data => ({ | |
match: `${data.HomeTeamNameInTournament} vs. ${data.AwayTeamNameInTournament}`, | |
result: `${data.MatchResultList.FinalResult.HomeTeamGoals} - ${data.MatchResultList.FinalResult.AwayTeamGoals}` , | |
squad: extractSquad(data, SquadId).join("; ") | |
})) | |
.catch(console.log) | |
const getMatch = async (MatchId, SquadId) => | |
await fetch(`https://fiks.fotball.no/FiksWeb/MatchReport/GetMatch/${MatchId}`, {...config(squadRefefer(MatchId))}) | |
.then( response=> response.json()) | |
.then( ({data})=> data) | |
const getAllMatches = async (SquadId) => | |
await fetch(`https://fiks.fotball.no/FiksWeb/Team/GetMatches?teamId=${SquadId}&_=1746504817052`, {...config(squadRefefer(SquadId))}) | |
.then( response=> response.json()) | |
.then (({Matches}) => Matches.sort( (a,b) => a.TournamentRoundNumber - b.TournamentRoundNumber)) | |
const getPlayedMatches = (SquadId) => getAllMatches(SquadId) | |
.then(result=> result.filter( ({Result}) => Boolean(Result))) | |
const getTorunamentSquad = async (SquadId) => | |
getPlayedMatches(SquadId) | |
.then(tournament => | |
Promise.all(tournament.map(async ({MatchId}) => await getMatchSquad(MatchId, SquadId)))) | |
//test | |
const NIF1 = 6540; | |
const NIF2 = 137968; | |
const NIF4 = 146403; | |
const NIF3 = 120992; | |
const g = window || global; | |
g.fiks = async ()=> await Promise.all([NIF1, NIF2, NIF3, NIF4].map((teamId) => getTorunamentSquad(teamId))); | |
const getPrevMatches = (SquadId) => { | |
await matches = getAllMatches(SquadId); | |
const prevMatch = (RoundNr) => matches.filter(({TournamentRoundNumber}) => TournamentRoundNumber === RoundNr - 1).shift(); | |
return matches.filter(match => !match.IsFutureMatch || prevMatch(match.TournamentRoundNumber)?.IsFutureMatch === false) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment