-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
28 lines (25 loc) · 983 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { checkAirtableInitialized, updateTeamRecord, addTeamToAirtable } from './scripts/airtableUtils.js';
import { getLeagueAPI, getTeamData, getMatchupOdds } from './scripts/apiUtils.js';
import { getTeamsArray, addAirtableIDs } from './scripts/dataProcessing.js';
import { config } from './scripts/config.js';
(async function main() {
const hasInitialized = await checkAirtableInitialized();
const apiData = await getLeagueAPI(`${config.BASE_API_URL}${config.SEASON_YEAR}`);
if (!apiData) {
console.log("No data was fetched from the API.");
return;
}
const teamsArray = await getTeamsArray(apiData);
let extendedTeams = await getTeamData(teamsArray);
let teamsWithOdds = await getMatchupOdds(extendedTeams);
const teams = await addAirtableIDs(teamsWithOdds);
if (hasInitialized) {
for (const team of teams) {
await updateTeamRecord(team);
}
} else {
for (const team of teams) {
await addTeamToAirtable(team);
}
}
})();