()
| 145 | } |
| 146 | |
| 147 | function getQuestions() { |
| 148 | return new Promise((resolve) => { |
| 149 | $.get(taskUrl('mcxhd_brandcity_getQuestions'), async (err, resp, data) => { |
| 150 | try { |
| 151 | if (err) { |
| 152 | console.log(`${JSON.stringify(err)}`) |
| 153 | console.log(`${$.name} API请求失败,请检查网路重试`) |
| 154 | } else { |
| 155 | data = JSON.parse(data); |
| 156 | if (data && data['retCode'] === "200") { |
| 157 | console.log(`答题开启成功`) |
| 158 | let i = 0, questionList = [] |
| 159 | for (let vo of data.result.questionList) { |
| 160 | $.question = vo |
| 161 | let option = null, hasFound = false |
| 162 | |
| 163 | console.log(`去查询第${++i}题:【${vo.questionStem}】`) |
| 164 | let ques = $.tk.filter(qo => qo.questionId === vo.questionId) |
| 165 | |
| 166 | if (ques.length) { |
| 167 | ques = ques[0] |
| 168 | let ans = JSON.parse(ques.correct) |
| 169 | let opt = vo.options.filter(bo => bo.optionDesc === ans.optionDesc) |
| 170 | if (opt.length) { |
| 171 | console.log(`在脚本内置题库中找到题啦~`) |
| 172 | option = opt[0] |
| 173 | hasFound = true |
| 174 | } else { |
| 175 | console.log(`在脚本内置题库中 未找到答案,去线上题库寻找~`); |
| 176 | ques = await getQues(vo.questionId) |
| 177 | if (ques) { |
| 178 | let ans = JSON.parse(ques.correct) |
| 179 | let opt = vo.options.filter(bo => bo.optionDesc === ans.optionDesc) |
| 180 | if (opt.length) { |
| 181 | console.log(`在线上题库中找到题啦~`) |
| 182 | option = opt[0] |
| 183 | hasFound = true |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | if (!option) { |
| 190 | console.log(`在题库中未找到题`) |
| 191 | let ans = -1 |
| 192 | for (let opt of vo.options) { |
| 193 | let str = vo.questionStem + opt.optionDesc |
| 194 | console.log(`去搜索${str}`) |
| 195 | let res = await bing(str) |
| 196 | if (res > ans) { |
| 197 | option = opt |
| 198 | ans = res |
| 199 | } |
| 200 | await $.wait(2 * 1000) |
| 201 | } |
| 202 | if (!option) { |
| 203 | option = vo.options[1] |
| 204 | console.log(`未找到答案,都选B【${option.optionDesc}】\n`) |
no test coverage detected