昨天成功得到10组不重复的乱数验证码,今天要把产好的验证码写进 Google Sheet。
verification_code
先前提过,Google Sheet 可以看作是 Database,而里面的工作表可以看成是 table,所以我们就在之前的 auto-get-verification-code
Google Sheet 新增ㄧ张工作表叫 verification_code
。
注意:记得把第一行的资料格式设成纯文字,验证码塞入後才不会被误判为数字类型
Read Mail
专案接着我们修改一下 Read Mail
中的 connectToSheet.gs
以扩充使用情境
修改 connectToSheet.gs
如以下内容
sheetName
可用 sheet name 取得指定的工作表function connectToSheet(sheetName) {
Logger.log('start to connectToSheet');
var spreadSheet = SpreadsheetApp.openById('your_spread_sheet_id');
var sheet = spreadSheet.getSheetByName(sheetName);
if (sheet != null) {
return sheet;
}
throw Error;
}
接着修改 app.gs
中有用到 connectToSheet
的地方
function app(userId) {
var content = readMail();
var sheet = connectToSheet('contents');
insertToSheet(sheet, content, userId);
return content;
}
接着修改 generateVerificationCode.gs 如下:
verificationCode[]
时,改成塞入 array [front+end]
,这是因为我们要塞进 Google Sheet 时,每一个验证码就塞一个 RowinsertVerificationCode
function,利用 ReadMailAndInsertToGoogleSheet
连线到 verification_code
sheet,并且将验证码写入 Google Sheetfunction generateVerificationCode() {
var amount = 10;
var verificationCode = [];
var i = 0;
var front = "";
var end = "";
while ( i < amount) {
front = (((1 + Math.random()) * 0x10000)|0).toString(16).substring(1);
end = (((1 + Math.random()) * 0x10000)|0).toString(16).substring(1);
verificationCode.push([front+end]);
i++;
}
var uniqueVerificationCode = [...new Set(verificationCode)];
insertVerificationCode(uniqueVerificationCode);
}
function insertVerificationCode(uniqueVerificationCode) {
var sheet = ReadMailAndInsertToGoogleSheet.connectToSheet('verification_code');
var range = sheet.getRange(1, 1, uniqueVerificationCode.length, 1);
range.setValues(uniqueVerificationCode);
}
修改後记得存档!然後我们就执行 generateVerificationCode 看看结果:
有成功写入验证码了!
今天就先到这里~补班是身体跟心灵的双重打击啊(倒)
希望明天台风可以平安无事!明天假日再来多完成一些进度罗~
<<: 铁人赛 Day11-- PHP SQL基本语法(六) -- INSERT 基本语法
Chap.IV Data Services 资料库服务 SQL Databases SQL 资料库 ...
Tag:随意刷-未写过的 Source: 995. Minimum Number of K Cons...
在[Day 16]和[Day 17]「TFLM + BLE Sense + MP34DT05 就成了...
前面我们使用pvc放置训练好的model档好让seldon可以读取, 但放置模型档到pvc之中的过程...
今天将会介绍程序中的数学运算,并且学习python的逻辑判断。 数学运算 Python也可以拿来当计...