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')
    
  • 相关阅读:
    Eureka 原理圖
    RabbitMQ 介紹
    rabbitmq-3.5.1-安裝
    MyBatis 基础入门
    CSS
    程序员必会算法-KMP算法
    编程这些年
    排序算法之直接插入排序
    排序算法之选择排序
    排序算法之冒泡排序
  • 原文地址:https://www.cnblogs.com/chengyunshen/p/13411701.html
Copyright © 2011-2022 走看看