1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
function CreateAndUploadJson() { const domain = "xxxxxxxx" createCategoryData(domain) UploadJson(domain) }
function CreateAndUploadAll() { const domain = ["audio-takakuureru", "beauty-takakuureru", "bicycle-takakuureru", "brand-takakuureru", "camera-takakuureru", "delivery-kaitori", "figure-takakuureru", "fishing-takakuureru", "g-takakuureru", "gakki-takakuureru", "guitar-kaitori", "gun-takakuureru", "kaden-takakuureru", "kagu-takakuureru", "kenki-takakuureru", "kougu-takakuureru", "navi-takakuureru", "noukigu-takakuureru", "pc-takakuureru", "sax-takakuureru", "sports-takakuureru", "syuttyou-kaitori", "tokei-takakuureru", "train-takakuureru", "tv-takakuureru"] domain.forEach(json_domain => { createCategoryData(json_domain) UploadJson(json_domain) }) }
function UploadJson(domain) { var accessKey = 'xxxxxxxxxx'; var secretKey = "xxxxxxxxxx" var bucketName = "xxxxxxxxx" var spreadsheetId = 'xxxxxxxxxxxx' var sheetName = domain; const ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheetByName(sheetName); var data = String(sheet.getRange('A:A').getValues()); while (data.charAt(data.length - 1) == ',') { data = data.substr(0, data.length - 1); } json = Utilities.newBlob(data, "application/json"); var s3 = S3.getInstance(accessKey, secretKey); var response = s3.putObject(bucketName, sheetName + '.json', json, { logRequests: true }); Logger.log(response); }
function createCategoryData(sheetName) { var sheet = SpreadsheetApp.getActive().getSheetByName(sheetName + '-data'); var dataArray = convSheet(sheet); creatNewSheet(dataArray, sheetName); }
function convSheet(sheet) { let categoryJson = [] Logger.log(sheet) var jsonRange = sheet.getRange(2, 2, sheet.getLastRow() - 1, sheet.getLastColumn() - 1); var jsonRowValues = jsonRange.getValues(); for (let i = 0; i < jsonRowValues.length; i++) { const catLvlObj = categoryJson.filter(cat0 => cat0.title === jsonRowValues[i][0]) if (!!Object.keys(catLvlObj).length) { const cat1LvlObj = catLvlObj[0].options.filter(cat1 => cat1.title === jsonRowValues[i][1]) const att = CreateJson(jsonRowValues[i][5]) if (!!Object.keys(cat1LvlObj).length) { cat1LvlObj[0].options.push({ id: jsonRowValues[i][5], title: jsonRowValues[i][2], category: jsonRowValues[i][6], attributes: att }) } else { catLvlObj[0].options.push({ id: jsonRowValues[i][4], title: jsonRowValues[i][1], options: [{ id: jsonRowValues[i][5], title: jsonRowValues[i][2], category: jsonRowValues[i][6], attributes: att }] }) } } else { let catNew = new Object catNew.id = jsonRowValues[i][3] catNew.title = jsonRowValues[i][0] const att = CreateJson(jsonRowValues[i][5]) catNew.options = [{ id: jsonRowValues[i][4], title: jsonRowValues[i][1], options: [{ id: jsonRowValues[i][5], title: jsonRowValues[i][2], category: jsonRowValues[i][6], attributes: att }] }] categoryJson.push(catNew) } } return categoryJson }
function creatNewSheet(dataArray, sheetName) { var json = JSON.stringify(dataArray); var newSheetName = sheetName; var newSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(newSheetName); if (!newSheet) { newSheet = SpreadsheetApp.getActiveSpreadsheet(); newSheet.insertSheet(newSheetName); newSheet.getRange("A1").setValue(json); } else { newSheet.getRange("A1").setValue(String(json)); } }
function CreateJson(cat2_id) { const ss = SpreadsheetApp.getActiveSpreadsheet(); const fieldSheet = ss.getSheetByName("抽出_format"); const elementSheet = ss.getSheetByName("m_format_element"); const fieldData = fieldSheet.getDataRange().getValues(); const elementData = elementSheet.getDataRange().getValues(); let value = [] for (let i = 2; i < fieldData.length; i++) { const row = fieldData[i] const outputFlg = row[0] if (outputFlg === 0) continue; let inputHint = row[2]; const sort = row[4]; const categoryId = row[6]; const formatId = row[7]; const name = row[9]; const formatType = row[13]; const fieldKey = row[14]; const rules = [] const required = row[3]; const maxLength = row[10]; if (required === 1) { rules.push("required") } if (maxLength !== "") { rules.push(`max:${maxLength}`) } let elements; if (formatType === "select" || formatType === "radio") { elements = elementData.filter(row => row[0] === formatId).map(row => row[2]) if (formatType === "radio") { const radioObj = [] elements.map(el => radioObj.push({ label: el, value: el })) elements = radioObj } } if (row[6] === Number(cat2_id)) { value.push({ "field_name": name, "field_key": fieldKey, "type": formatType, "required": `${required === 1}`, "rules": `${rules.length > 0 ? rules.join("|") : ""}`, "options": elements === null ? "" : elements, "hint": `${inputHint === null ? "" : inputHint}`, "sort": sort, "format_id": formatId }) } } return value }
|