Code Samples - CSC4790-Fall2024-Org/Sports-Betting-Tool GitHub Wiki
Code to use string matching for team names:
const findMatchingOdd = (odds, targetName, market) => {
if (market.toLowerCase().includes('moneyline')) {
return odds?.find(odd => {
const targetTeam = targetName.toLowerCase().replace(/\s+/g, '');
const oddTeam = odd.name.toLowerCase().replace(/\s+/g, '');
return targetTeam === oddTeam;
});
}
return odds?.find(odd => odd.name === targetName);
};
Code for caching odds and refresh functionality:
@csrf_exempt
def get_odds(request):
cached_data = cache.get("odds_data")
if cached_data:
return JsonResponse(cached_data)
odds_data = fetch_sportsbook_data()
cache.set("odds_data", odds_data, timeout=3600) # Cache for 1 hour
return JsonResponse(odds_data)
@csrf_exempt
def refresh_odds(request):
odds_data = fetch_sportsbook_data()
cache.set("odds_data", odds_data, timeout=3600)
return JsonResponse(odds_data)