zoukankan      html  css  js  c++  java
  • node脚本下载geo数据

    var fs = require("fs");
    var path = require("path");
    var request = require("request");
    
    //创建文件夹目录
    var dirPath = path.join(__dirname, "geos");
    if (!fs.existsSync(dirPath)) {
        fs.mkdirSync(dirPath);
        console.log("文件夹创建成功");
    } else {
        console.log("文件夹已存在");
    }
    const  url = 'https://geo.datav.aliyun.com/areas_v2/bound/';
    function downFile(fileName){	
    	request(url + fileName,function(err, response, body){
    		console.log(typeof body,"type")
    		let data = JSON.stringify(JSON.parse((body)))
    		if(fileName === 'all.json'){
    			JSON.parse(body).map(item=>{
    				if(item.level == 'country' || item.level=="province")
    				{
    					downFile(item.adcode+'_full.json')
    				}
    			})
    			data =  JSON.stringify( JSON.parse(body).filter(item => item.level =='country' || item.level =='province'))
    		}
    		 let stream = fs.createWriteStream(path.join(dirPath, fileName));
    		 stream.write(data)
    	})
    }
    downFile('all.json')
    
  • 相关阅读:
    indexOf & lastIndexOf
    document.referrer
    函数组合
    v-model绑定vuex中的数据
    图片懒加载
    flex布局问题
    js常见错误类型
    es5/es6继承的区别
    合并两个有序数组
    lettcode 90 子集II
  • 原文地址:https://www.cnblogs.com/chengyunshen/p/13411701.html
Copyright © 2011-2022 走看看