为什么一个文件会创建应用程序脚本错误?
你能帮我理解为什么这个脚本对双倍赔率不起作用吗?这是我试图从中获取信息的地方:
当我更改源中的值时,就像我对其他人所做的那样,它给了我一个错误。我相信这是因为,与其他道具类型不同,双倍要么是/否,而不是上/下。这是带有脚本的谷歌表!我需要有关名为 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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于有时对象
outcome[1]
未定义,因此您需要捕获这些情况。尝试这些修改来解决这些可能的问题:脚本修改:
修改的作用是检查对象
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:
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 callConditional (ternary) operator
. Its form iscondition ? true : false
.Output:
Note:
outcome[0]
in the check since it seems like they are always defined. If it errors and points to theoutcome[0]
lines, then do the same thing we did above.