Advertisement
RemcoE33

Baseballpress lineup

Jul 2nd, 2022
862
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.60 KB | None
  1.  
  2. /**
  3. * Returns lineups from baseballpress
  4. *
  5. * @param {"2022-07-01"} date date in international format
  6. * @return {array} team, player, temp,
  7. * @customfunction
  8. */
  9. function BASEBALLPRESS(date = "2022-07-01") {
  10.  
  11.   const request = UrlFetchApp.fetch(`https://www.baseballpress.com/lineups/${date}`)
  12.   const html = request.getContentText();
  13.  
  14.   const results = [['Date', 'Time', 'Temp', 'Precip', 'Team', 'Player', 'Info', 'Url']];
  15.   const lineupsArray = [];
  16.   const lineupReg = /<div class="lineup-card-header">(.*?)<div class="lineup-card">/gmsi
  17.   let lineupResult;
  18.   while ((lineupResult = lineupReg.exec(html)) !== null) {
  19.     lineupsArray.push(lineupResult[1])
  20.   }
  21.  
  22.   lineupsArray.forEach(lineup => {
  23.     const date = /<div class="col col--min c">[\s\S]*?<div class="col col--min c">[\s\S]*?<div>(.*?)</gmsi.exec(lineup)[1]
  24.     const time = /<div class="col col--min c">[\s\S]*?<div class="col col--min c">[\s\S]*?<div>.*?<\/div>[\s\S]*?<div>(.*?)</gmsi.exec(lineup)[1]
  25.     const temp = /Gametime Temp: (.*?)</gmsi.exec(lineup)[1].replace(`&deg;`, '°');
  26.     const precip = `${/Chance of Precip: (.*?)&/gmsi.exec(lineup)[1]}%`
  27.  
  28.     const teamsArray = []
  29.     const teamsReg = /<\/svg>\s*<div>(.*?)</gmsi
  30.     let teamsResult;
  31.     while ((teamsResult = teamsReg.exec(lineup)) !== null) {
  32.       teamsArray.push(teamsResult[1])
  33.     }
  34.  
  35.     const playersReg = /<div class="lineup-card-body"><div class="row row--no-margin h-100">(.*?)<\/div><\/div>/gmsi.exec(lineup)[1]
  36.     const playersSplitByTeam = playersReg.split('<div class="col col--min">')
  37.     playersSplitByTeam.filter(team => team.length > 10).forEach((team, i) => {
  38.  
  39.       const nameReg = /data-razz="[\s\S]*?">(.*?)<\/a>/gmsi
  40.       const urlReg = /data-razz="(.*?)"/gmsi
  41.       const infoReg = /data-razz="[\s\S]*?<\/a> (.*?)<\/div>/gmsi
  42.  
  43.       const urlArray = []
  44.       const infoArray = []
  45.       const nameArray = []
  46.  
  47.       let url;
  48.       let name;
  49.       let info;
  50.  
  51.       while ((name = nameReg.exec(team)) !== null) {
  52.         if (name[1].includes('desktop-name')) {
  53.           name = /desktop-name">(.*?)</gmsi.exec(name)
  54.         }
  55.         nameArray.push(name[1])
  56.       }
  57.  
  58.       while ((info = infoReg.exec(team)) !== null) {
  59.         infoArray.push(info[1])
  60.       }
  61.  
  62.       while ((url = urlReg.exec(team)) !== null) {
  63.         urlArray.push(url[1])
  64.       }
  65.  
  66.       nameArray.forEach((name, j) => {
  67.         results.push([
  68.           date,
  69.           time,
  70.           temp,
  71.           precip,
  72.           teamsArray[i],
  73.           name,
  74.           infoArray[j],
  75.           urlArray[j]
  76.         ])
  77.       })
  78.  
  79.     })
  80.   })
  81.  
  82.   return results
  83.  
  84. }
Advertisement
RAW Paste Data Copied
Advertisement