(cityPath, offset)
| 326 | |
| 327 | |
| 328 | function pullCountryDataSync(cityPath, offset) { |
| 329 | offset = offset || 0 |
| 330 | let data = fs.readFileSync(cityPath); |
| 331 | let jsonData = JSON.parse(data); |
| 332 | jsonData.slice(offset).forEach(function(element, index) { |
| 333 | let urls = []; |
| 334 | let url = element.url.replace('www.stats.gov.cn', IP); |
| 335 | log.debug("正在请求 => " + element.name + " => "+ element.url); |
| 336 | if (url){ |
| 337 | requestSync({ |
| 338 | url: url, |
| 339 | encoding: null |
| 340 | }, function(error, response, body) { |
| 341 | //空的文件内容必须是 [] |
| 342 | //特殊处理东莞市 |
| 343 | if(["441900000000", "442000000000", "460400000000"].includes(element.id)){ |
| 344 | urls = JSON.parse(fs.readFileSync(TownPath) || []); |
| 345 | urls = urls.concat(parseTown(iconv.decode(body, 'gb2312'), absolutePath(element.url))); |
| 346 | fs.writeFileSync(TownPath, JSON.stringify(urls)); |
| 347 | } else { |
| 348 | urls = JSON.parse(fs.readFileSync(CountryPath) || []); |
| 349 | urls = urls.concat(parseCountry(iconv.decode(body, 'gb2312'), absolutePath(element.url))); |
| 350 | fs.writeFileSync(CountryPath, JSON.stringify(urls)); |
| 351 | } |
| 352 | log.debug('foreach ==> ', offset + index); |
| 353 | }); |
| 354 | sleep(500); |
| 355 | } |
| 356 | }); |
| 357 | } |
| 358 | |
| 359 | |
| 360 |
nothing calls this directly
no test coverage detected