forked from artiely/Administrative-divisions-of-China
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_json.sh
executable file
·66 lines (61 loc) · 2.44 KB
/
export_json.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/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