Skip to content

Commit f521db9

Browse files
committed
Added Sports bet util
1 parent 042ed3d commit f521db9

3 files changed

Lines changed: 61 additions & 20 deletions

File tree

client/src/components/pages/Skeleton.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ import { GoogleOAuthProvider, GoogleLogin, googleLogout } from "@react-oauth/goo
33

44
import "../../utilities.css";
55
import "./Skeleton.css";
6-
import { getRandomSeason } from "../../utilities";
6+
import { getBets, getRandomGame } from "../../sports_bet_util";
77

88
//TODO: REPLACE WITH YOUR OWN CLIENT_ID
99
const GOOGLE_CLIENT_ID = "575558179875-rgo4ik0dami2mu3mb48gh9s761gpf0s6.apps.googleusercontent.com";
1010

1111
const Skeleton = ({ userId, handleLogin, handleLogout }) => {
12-
getRandomSeason()
13-
.then((json) => {
14-
const response = json["response"];
15-
const random = Math.floor(Math.random() * response.length);
16-
const game = response[random];
17-
console.log(game["teams"]["home"]["name"] + " vs " + game["teams"]["away"]["name"]);
12+
getRandomGame()
13+
.then((id) => {
14+
// console.log(id);
15+
getBets(id)
16+
.then((bets) => console.log(bets))
1817
})
1918

2019
return (

client/src/sports_bet_util.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
export function getRandomGame() {
2+
const year = 2023 // Math.floor(Math.random() * 7 + 2015);
3+
const url = `https://v1.basketball.api-sports.io/odds?league=12&season=${year + "-" + (year+1)}`
4+
return fetch(url, {
5+
method: "GET",
6+
headers: {
7+
"x-rapidapi-key": "8097ad8b9eb665d99d8e442839cce0cc"
8+
}
9+
})
10+
.then((response) => response.json())
11+
.then((json) => {
12+
const response = json["response"];
13+
// console.log(response);
14+
const random = Math.floor(Math.random() * response.length);
15+
const game = response[random]["game"];
16+
// console.log(game["teams"]["home"]["name"] + " vs " + game["teams"]["away"]["name"]);
17+
return game["id"]
18+
})
19+
.catch((error) => {
20+
throw `GET request to "${url}" failed with error:\n${error}`
21+
})
22+
}
23+
24+
export function getBets(gameId) {
25+
const url = `https://v1.basketball.api-sports.io/odds?game=${gameId}`
26+
return fetch(url, {
27+
method: "GET",
28+
headers: {
29+
"x-rapidapi-key": "8097ad8b9eb665d99d8e442839cce0cc"
30+
}
31+
})
32+
.then((response) => response.json())
33+
.then((json) => {
34+
console.log(json);
35+
const bookmakers = json["response"][0]["bookmakers"];
36+
for (let i = 0; i < bookmakers.length; i ++) {
37+
if (bookmakers[i]["name"] === "Marathon Bet") {
38+
console.log("Found Marathon bet")
39+
const bets = bookmakers[i]["bets"];
40+
let targetBetNames = [
41+
"Home/Away",
42+
"Highest Scoring Quarter"
43+
]
44+
let targetBets = {}
45+
for (let j = 0; j < bets.length; j ++) {
46+
if (targetBetNames.includes(bets[j]["name"])) {
47+
targetBets[bets[j]["name"]] = bets[j];
48+
}
49+
}
50+
return targetBets
51+
}
52+
}
53+
return {}
54+
})
55+
}

client/src/utilities.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,4 @@ export function post(endpoint, params = {}) {
6262
});
6363
}
6464

65-
export function getRandomSeason() {
66-
const year = Math.floor(Math.random() * 7 + 2015);
6765

68-
return fetch(`https://v1.basketball.api-sports.io/games?league=12&season=${year + "-" + (year+1)}`, {
69-
method: "GET",
70-
headers: {
71-
"x-rapidapi-key": "8097ad8b9eb665d99d8e442839cce0cc"
72-
}
73-
})
74-
.then((response) => response.json())
75-
.catch((error) => {
76-
throw `GET request to "https://v1.basketball.api-sports.io/games?league=12&season=${year + "-" + (year+1)}" failed with error:\n${error}`
77-
})
78-
}

0 commit comments

Comments
 (0)