为什么一个文件会创建应用程序脚本错误?

发布于 2025-01-13 14:26:21 字数 2478 浏览 0 评论 0原文

你能帮我理解为什么这个脚本对双倍赔率不起作用吗?这是我试图从中获取信息的地方:

https://sportsbook.draftkings.com/leagues/basketball/88670846?category=player-props&subcategory=double-double

当我更改源中的值时,就像我对其他人所做的那样,它给了我一个错误。我相信这是因为,与其他道具类型不同,双倍要么是/否,而不是上/下。这是带有脚本的谷歌表!我需要有关名为 Double Double 的文件的帮助。

https://docs.google.com/spreadsheets/d/1ecZFvHwrhRC6Vn3gM67cTjYKmqOslarln-91aLeURJ4/edit?usp=sharing

这是编写的代码,但我收到错误:

function SPORTBOOK_DD() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheetByName('DD');
  const url = `https://sportsbook.draftkings.com//sites/US-SB/api/v4/eventgroups/88670846/categories/583/subcategories/7136?format=json`

  const response = UrlFetchApp.fetch(url);
  const rawData = JSON.parse(response.getContentText());
  const events = rawData.eventGroup.events;
  const offerCatergories = rawData.eventGroup.offerCategories;
  const playerProps = offerCatergories.filter(offer => offer.offerCategoryId == 583)[0];
  const pointsByEvent = playerProps.offerSubcategoryDescriptors.filter(sub => sub.subcategoryId == 7136)[0].offerSubcategory.offers;

  const output = [];

  pointsByEvent.forEach((eventPoint, i) => {
    const { name, startDate, teamName1, teamName2 } = events[i];
    eventPoint.forEach((point, j) => {
      const outcome = point.outcomes;
      const object = {
        Event: name,
        Startdate: startDate,
        Team1: teamName1,
        Team2: teamName2,
        Player: outcome[0].participant,
        Over_American: outcome[0].oddsAmerican,
        Over_Decimal: outcome[0].oddsDecimal,
        Over_Fractional: outcome[0].oddsFractional,
        Over_Line: outcome[0].line,
        Under_American: outcome[1].oddsAmerican,
        Under_Decimal: outcome[1].oddsDecimal,
        Under_Fractional: outcome[1].oddsFractional,
        Under_Line: outcome[1].line
      }

      if (i == 0 && j == 0) {
        output.push(Object.keys(object));
      };

      output.push(Object.values(object));
    });
  });

  sheet.getDataRange().clearContent();
  sheet.getRange(1, 1, output.length, output[0].length).setValues(output);

}

Can you help me understand why the script isn't working for the double double odds? Here is the place that I am trying to get the information from:

https://sportsbook.draftkings.com/leagues/basketball/88670846?category=player-props&subcategory=double-double

When I change the value in the source, as I did for the others, it gives me an error. I believe it is because, unlike the other prop types, double double is either Yes/No instead of Over/Under. Here is the googlesheet with the script! I need help with the file named Double Double.

https://docs.google.com/spreadsheets/d/1ecZFvHwrhRC6Vn3gM67cTjYKmqOslarln-91aLeURJ4/edit?usp=sharing

Here is the code written but I am getting an error:

function SPORTBOOK_DD() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheetByName('DD');
  const url = `https://sportsbook.draftkings.com//sites/US-SB/api/v4/eventgroups/88670846/categories/583/subcategories/7136?format=json`

  const response = UrlFetchApp.fetch(url);
  const rawData = JSON.parse(response.getContentText());
  const events = rawData.eventGroup.events;
  const offerCatergories = rawData.eventGroup.offerCategories;
  const playerProps = offerCatergories.filter(offer => offer.offerCategoryId == 583)[0];
  const pointsByEvent = playerProps.offerSubcategoryDescriptors.filter(sub => sub.subcategoryId == 7136)[0].offerSubcategory.offers;

  const output = [];

  pointsByEvent.forEach((eventPoint, i) => {
    const { name, startDate, teamName1, teamName2 } = events[i];
    eventPoint.forEach((point, j) => {
      const outcome = point.outcomes;
      const object = {
        Event: name,
        Startdate: startDate,
        Team1: teamName1,
        Team2: teamName2,
        Player: outcome[0].participant,
        Over_American: outcome[0].oddsAmerican,
        Over_Decimal: outcome[0].oddsDecimal,
        Over_Fractional: outcome[0].oddsFractional,
        Over_Line: outcome[0].line,
        Under_American: outcome[1].oddsAmerican,
        Under_Decimal: outcome[1].oddsDecimal,
        Under_Fractional: outcome[1].oddsFractional,
        Under_Line: outcome[1].line
      }

      if (i == 0 && j == 0) {
        output.push(Object.keys(object));
      };

      output.push(Object.values(object));
    });
  });

  sheet.getDataRange().clearContent();
  sheet.getRange(1, 1, output.length, output[0].length).setValues(output);

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国粹 2025-01-20 14:26:21

由于有时对象 outcome[1] 未定义,因此您需要捕获这些情况。尝试这些修改来解决这些可能的问题:

脚本修改:

Under_American: outcome[1] ? outcome[1].oddsAmerican : '',
Under_Decimal: outcome[1] ? outcome[1].oddsDecimal : '',
Under_Fractional: outcome[1] ? outcome[1].oddsFractional : '',
Under_Line: outcome[1] ? outcome[1].line : ''

修改的作用是检查对象 outcome[1] 是否已定义。如果是,则正常赋值。如果不是,则指定一个空字符串。这只是一个简化的 if/else 语句,我们称之为条件(三元)运算符。其形式为 condition ?真:假

输出:

输出

注意:

  • 我没有在检查中包含 outcome[0] 因为它们似乎总是被定义的。如果它出错并指向 outcome[0] 行,则执行与上面相同的操作。

Since there are times the object outcome[1] is undefined, you need to catch those circumstances. Try these modifications for those possible issues:

Script Modification:

Under_American: outcome[1] ? outcome[1].oddsAmerican : '',
Under_Decimal: outcome[1] ? outcome[1].oddsDecimal : '',
Under_Fractional: outcome[1] ? outcome[1].oddsFractional : '',
Under_Line: outcome[1] ? outcome[1].line : ''

What the modification does is that it will check if the object outcome[1] is defined. If it is, then assign the value normally. If not, assign a blank string. This is just a simplified if/else statement we call Conditional (ternary) operator. Its form is condition ? true : false.

Output:

output

Note:

  • I haven't included outcome[0] in the check since it seems like they are always defined. If it errors and points to the outcome[0] lines, then do the same thing we did above.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文