Skip to content

Instantly share code, notes, and snippets.

@isaacssemugenyi
Created October 11, 2022 07:50
Show Gist options
  • Save isaacssemugenyi/edfe3079d23fdb997f24c17a343849ce to your computer and use it in GitHub Desktop.
Save isaacssemugenyi/edfe3079d23fdb997f24c17a343849ce to your computer and use it in GitHub Desktop.
Extract data from a json response
exports.manupilateOdds = (response) => {
const odds = [];
for (const index in response) {
response[index].fixture.index = parseInt(index)
response[index].bookmaker = response[index].bookmakers[0]
delete response[index].league
delete response[index].update
delete response[index].bookmakers
odds.push({
fixture_id: response[index].fixture.id,
fixture_timestamp: response[index].fixture.timestamp,
bets: response[index].bookmaker.bets
})
}
return manupilateBets(odds);
}
function manupilateBets(data){
const bets = []
for(let index in data){
const currentBets = data[index].bets
for(let iterator in data[index].bets){
bets.push({
fixture_id: data[index].fixture_id,
fixture_timestamp: data[index].fixture_timestamp,
bet_id: currentBets[iterator].id,
bet_name: currentBets[iterator].name,
bet_values: currentBets[iterator].values
})
}
}
return constructMatchOdds(bets);
}
function constructMatchOdds(bets){
const odds = [];
for(let index in bets){
const currentOdds = bets[index].bet_values;
for(let iterator in bets[index].bet_values){
odds.push({
fixture_id: bets[index].fixture_id,
fixture_timestamp: bets[index].fixture_timestamp,
bet_id: bets[index].bet_id,
bet_name: bets[index].bet_name,
odd_name: currentOdds[iterator].value,
odd_no: parseFloat(currentOdds[iterator].odd)
})
}
}
return odds;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment