Advertisement
RemcoE33

fuegobudkush - draftkings

Aug 16th, 2022
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. * Returns draftking event information.
  3. *
  4. * @return {array} information.
  5. * @customfunction
  6. */
  7. function DRAFKING_MLB() {
  8.   const url = `https://sportsbook.draftkings.com//sites/US-SB/api/v5/eventgroups/84240/categories/1031/subcategories/9884?format=json`
  9.   const request = UrlFetchApp.fetch(url)
  10.   const data = JSON.parse(request.getContentText())
  11.  
  12.   const offers = []
  13.   const events = []
  14.  
  15.   data.eventGroup.events.forEach(event => {
  16.     const eventInfo = {
  17.       eventId: event.eventId,
  18.       name: event.name,
  19.       startDate: event.startDate,
  20.       team1: event.teamName1,
  21.       team2: event.teamName2,
  22.       status: event.eventStatus.state
  23.     }
  24.     events.push(eventInfo)
  25.   })
  26.  
  27.   const category = data.eventGroup.offerCategories.find(cat => cat.offerCategoryId == 1031)
  28.   const subcategorie = category.offerSubcategoryDescriptors.find(sub => sub.subcategoryId == 9884)
  29.  
  30.   subcategorie.offerSubcategory.offers.forEach(mainOffer => {
  31.     mainOffer.forEach(offer => {
  32.       offer.outcomes.forEach(outcome => {
  33.         const info = {
  34.           ...events.find(e => e.eventId == offer.eventId),
  35.           isSuspended: offer.isSuspended,
  36.           isOpen: offer.isOpen,
  37.           participant: outcome.participant,
  38.           label: outcome.label,
  39.           oddsAmerican: outcome.oddsAmerican,
  40.           oddsDecimal: outcome.oddsDecimal,
  41.           oddsDecimalDisplay: outcome.oddsDecimalDisplay,
  42.           oddsFractional: outcome.oddsFractional
  43.         }
  44.         offers.push(info)
  45.       })
  46.     })
  47.   })
  48.  
  49.   const toSheetsArray = offers.map(offer => Object.values(offer))
  50.   toSheetsArray.unshift(Object.keys(offers[0]))
  51.  
  52.   return toSheetsArray
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement