1 Star 0 Fork 0

ityuha0/Administrative-divisions-of-China

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
export_json.sh 2.44 KB
一键复制 编辑 原始数据 按行查看 历史
modood 提交于 2018-02-04 13:12 . feat: 新增 csv, json 数据导出脚本
#!/usr/bin/env bash
sqlite3 ./dist/data.sqlite "SELECT code,name FROM province ORDER BY code;" | awk -F'|' '
{ code[++i]=$1; name[i]=$2 }
END {
printf "[";
for(j=1;j<=i;j++){
printf "{|code|:|%s|,|name|:|%s|",code[j],name[j]
closing="},"
if(j==i){closing="}"}
printf closing;
}
printf "]";
}' | tr '|' '"' > ./dist/provinces.json
sqlite3 ./dist/data.sqlite "SELECT code,name,provinceCode FROM city ORDER BY code;" | awk -F'|' '
{ code[++i]=$1; name[i]=$2; provinceCode[i]=$3 }
END {
printf "[";
for(j=1;j<=i;j++){
printf "{|code|:|%s|,|name|:|%s|,|provinceCode|:|%s|",code[j],name[j],provinceCode[j]
closing="},"
if(j==i){closing="}"}
printf closing;
}
printf "]";
}' | tr '|' '"' > ./dist/cities.json
sqlite3 ./dist/data.sqlite "SELECT code,name,cityCode,provinceCode FROM area ORDER BY code;" | awk -F'|' '
{ code[++i]=$1; name[i]=$2; cityCode[i]=$3; provinceCode[i]=$4 }
END {
printf "[";
for(j=1;j<=i;j++){
printf "{|code|:|%s|,|name|:|%s|,|cityCode|:|%s|,|provinceCode|:|%s|",code[j],name[j],cityCode[j],provinceCode[j]
closing="},"
if(j==i){closing="}"}
printf closing;
}
printf "]";
}' | tr '|' '"' > ./dist/areas.json
sqlite3 ./dist/data.sqlite "SELECT code,name,areaCode,cityCode,provinceCode FROM street ORDER BY code;" | awk -F'|' '
{ code[++i]=$1; name[i]=$2; areaCode[i]=$3; cityCode[i]=$4; provinceCode[i]=$5 }
END {
printf "[";
for(j=1;j<=i;j++){
printf "{|code|:|%s|,|name|:|%s|,|areaCode|:|%s|,|cityCode|:|%s|,|provinceCode|:|%s|",code[j],name[j],areaCode[j],cityCode[j],provinceCode[j]
closing="},"
if(j==i){closing="}"}
printf closing;
}
printf "]";
}' | tr '|' '"' > ./dist/streets.json
sqlite3 ./dist/data.sqlite "SELECT code,name,streetCode,areaCode,cityCode,provinceCode FROM village ORDER BY code;" | awk -F'|' '
{ code[++i]=$1; name[i]=$2; streetCode[i]=$3; areaCode[i]=$4; cityCode[i]=$5; provinceCode[i]=$6 }
END {
printf "[";
for(j=1;j<=i;j++){
printf "{|code|:|%s|,|name|:|%s|,|streetCode|:|%s|,|areaCode|:|%s|,|cityCode|:|%s|,|provinceCode|:|%s|",code[j],name[j],streetCode[j],areaCode[j],cityCode[j],provinceCode[j]
closing="},"
if(j==i){closing="}"}
printf closing;
}
printf "]";
}' | tr '|' '"' > ./dist/villages.json
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ityuha0/Administrative-divisions-of-China.git
[email protected]:ityuha0/Administrative-divisions-of-China.git
ityuha0
Administrative-divisions-of-China
Administrative-divisions-of-China
master

搜索帮助