export_json.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env bash
  2. sqlite3 ./dist/data.sqlite "SELECT code,name FROM province ORDER BY code;" | awk -F'|' '
  3. { code[++i]=$1; name[i]=$2 }
  4. END {
  5. printf "[";
  6. for(j=1;j<=i;j++){
  7. printf "{|code|:|%s|,|name|:|%s|",code[j],name[j]
  8. closing="},"
  9. if(j==i){closing="}"}
  10. printf closing;
  11. }
  12. printf "]";
  13. }' | tr '|' '"' > ./dist/provinces.json
  14. sqlite3 ./dist/data.sqlite "SELECT code,name,provinceCode FROM city ORDER BY code;" | awk -F'|' '
  15. { code[++i]=$1; name[i]=$2; provinceCode[i]=$3 }
  16. END {
  17. printf "[";
  18. for(j=1;j<=i;j++){
  19. printf "{|code|:|%s|,|name|:|%s|,|provinceCode|:|%s|",code[j],name[j],provinceCode[j]
  20. closing="},"
  21. if(j==i){closing="}"}
  22. printf closing;
  23. }
  24. printf "]";
  25. }' | tr '|' '"' > ./dist/cities.json
  26. sqlite3 ./dist/data.sqlite "SELECT code,name,cityCode,provinceCode FROM area ORDER BY code;" | awk -F'|' '
  27. { code[++i]=$1; name[i]=$2; cityCode[i]=$3; provinceCode[i]=$4 }
  28. END {
  29. printf "[";
  30. for(j=1;j<=i;j++){
  31. printf "{|code|:|%s|,|name|:|%s|,|cityCode|:|%s|,|provinceCode|:|%s|",code[j],name[j],cityCode[j],provinceCode[j]
  32. closing="},"
  33. if(j==i){closing="}"}
  34. printf closing;
  35. }
  36. printf "]";
  37. }' | tr '|' '"' > ./dist/areas.json
  38. sqlite3 ./dist/data.sqlite "SELECT code,name,areaCode,cityCode,provinceCode FROM street ORDER BY code;" | awk -F'|' '
  39. { code[++i]=$1; name[i]=$2; areaCode[i]=$3; cityCode[i]=$4; provinceCode[i]=$5 }
  40. END {
  41. printf "[";
  42. for(j=1;j<=i;j++){
  43. printf "{|code|:|%s|,|name|:|%s|,|areaCode|:|%s|,|cityCode|:|%s|,|provinceCode|:|%s|",code[j],name[j],areaCode[j],cityCode[j],provinceCode[j]
  44. closing="},"
  45. if(j==i){closing="}"}
  46. printf closing;
  47. }
  48. printf "]";
  49. }' | tr '|' '"' > ./dist/streets.json
  50. sqlite3 ./dist/data.sqlite "SELECT code,name,streetCode,areaCode,cityCode,provinceCode FROM village ORDER BY code;" | awk -F'|' '
  51. { code[++i]=$1; name[i]=$2; streetCode[i]=$3; areaCode[i]=$4; cityCode[i]=$5; provinceCode[i]=$6 }
  52. END {
  53. printf "[";
  54. for(j=1;j<=i;j++){
  55. 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]
  56. closing="},"
  57. if(j==i){closing="}"}
  58. printf closing;
  59. }
  60. printf "]";
  61. }' | tr '|' '"' > ./dist/villages.json