Skip to content

Commit

Permalink
feat: add hongkong.csv/macau.csv.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Mar 22, 2022
1 parent ec9f240 commit c28c3e9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ jobs:
| 县级(区县) | [area.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/area.json) ([min](https://github.com/uiwjs/province-city-china/blob/gh-pages/area.min.json)) | [area.csv](https://github.com/uiwjs/province-city-china/blob/gh-pages/area.csv) | - | [area.json](https://unpkg.com/province-city-china/dist/area.json) / [csv](https://unpkg.com/province-city-china/dist/area.csv) |
| 乡级(乡镇/街) | [town.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/town.json) ([min](https://github.com/uiwjs/province-city-china/blob/gh-pages/town.min.json)) | [town.csv](https://github.com/uiwjs/province-city-china/blob/gh-pages/town.csv) | - | [town.json](https://unpkg.com/province-city-china/dist/town.json) / [csv](https://unpkg.com/province-city-china/dist/town.csv) |
| 县市区没有乡级数据 | [not-found-town.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/not-found-town.json) ([min](https://github.com/uiwjs/province-city-china/blob/gh-pages/not-found-town.min.json)) | - | - | [not-found-town.json](https://unpkg.com/province-city-china/dist/not-found-town.json) |
| 香港澳门<区>数据 | [hongkong.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/hongkong.json) <br> [macau.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/macau.json) | - | - | [hongkong.json](https://unpkg.com/province-city-china/dist/hongkong.json) <br> [macau.json](https://unpkg.com/province-city-china/dist/macau.json) |
| 香港澳门<区>数据 | [hongkong.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/hongkong.json) <br> [macau.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/macau.json) | [hongkong.csv](https://github.com/uiwjs/province-city-china/blob/gh-pages/hongkong.csv) / [macau.csv](https://github.com/uiwjs/province-city-china/blob/gh-pages/macau.csv) | - | [hongkong.json](https://unpkg.com/province-city-china/dist/hongkong.json) ([csv](https://unpkg.com/province-city-china/dist/hongkong.csv)) <br> [macau.json](https://unpkg.com/province-city-china/dist/macau.json) ([csv](https://unpkg.com/province-city-china/dist/macau.csv)) |
| 国内长途电话区号 | [district-code.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/district-code.json) | [district-code.csv](https://github.com/uiwjs/province-city-china/blob/gh-pages/district-code.csv) | - | [district-code.json](https://unpkg.com/province-city-china/dist/district-code.json) / [csv](https://unpkg.com/province-city-china/dist/district-code.csv) |
| 包名 | 说明 | 版本 | 大小 |
| ---- | ---- | ---- | ---- |
| [province-city-china](https://github.com/uiwjs/province-city-china) | 包含所有包内容 | [![npm package](https://img.shields.io/npm/v/province-city-china.svg)](https://www.npmjs.com/package/province-city-china) | - |
Expand Down
4 changes: 2 additions & 2 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const city = require('province-city-china/dist/city.json');
| 县级(区县) | [area.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/area.json) ([min](https://github.com/uiwjs/province-city-china/blob/gh-pages/area.min.json)) | [area.csv](https://github.com/uiwjs/province-city-china/blob/gh-pages/area.csv) | - | [area.json](https://unpkg.com/province-city-china/dist/area.json) / [csv](https://unpkg.com/province-city-china/dist/area.csv) |
| 乡级(乡镇/街) | [town.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/town.json) ([min](https://github.com/uiwjs/province-city-china/blob/gh-pages/town.min.json)) | [town.csv](https://github.com/uiwjs/province-city-china/blob/gh-pages/town.csv) | - | [town.json](https://unpkg.com/province-city-china/dist/town.json) / [csv](https://unpkg.com/province-city-china/dist/town.csv) |
| 县市区没有乡级数据 | [not-found-town.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/not-found-town.json) ([min](https://github.com/uiwjs/province-city-china/blob/gh-pages/not-found-town.min.json)) | - | - | [not-found-town.json](https://unpkg.com/province-city-china/dist/not-found-town.json) |
| 香港澳门<区>数据 | [hongkong.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/hongkong.json) <br> [macau.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/macau.json) | - | - | [hongkong.json](https://unpkg.com/province-city-china/dist/hongkong.json) <br> [macau.json](https://unpkg.com/province-city-china/dist/macau.json) |
| 香港澳门<区>数据 | [hongkong.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/hongkong.json) <br> [macau.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/macau.json) | [hongkong.csv](https://github.com/uiwjs/province-city-china/blob/gh-pages/hongkong.csv) / [macau.csv](https://github.com/uiwjs/province-city-china/blob/gh-pages/macau.csv) | - | [hongkong.json](https://unpkg.com/province-city-china/dist/hongkong.json) ([csv](https://unpkg.com/province-city-china/dist/hongkong.csv)) <br> [macau.json](https://unpkg.com/province-city-china/dist/macau.json) ([csv](https://unpkg.com/province-city-china/dist/macau.csv)) |
| 国内长途电话区号 | [district-code.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/district-code.json) | [district-code.csv](https://github.com/uiwjs/province-city-china/blob/gh-pages/district-code.csv) | - | [district-code.json](https://unpkg.com/province-city-china/dist/district-code.json) / [csv](https://unpkg.com/province-city-china/dist/district-code.csv) |

更多 CDN 数据访问
Expand Down Expand Up @@ -413,7 +413,7 @@ town: 't'

### 香港澳门<区>数据

[hongkong.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/hongkong.json) | [macau.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/macau.json)
[hongkong.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/hongkong.json) | [hongkong.csv](https://github.com/uiwjs/province-city-china/blob/gh-pages/hongkong.csv) | [macau.json](https://github.com/uiwjs/province-city-china/blob/gh-pages/macau.json) | [macau.csv](https://github.com/uiwjs/province-city-china/blob/gh-pages/macau.csv)

```js
[
Expand Down
19 changes: 19 additions & 0 deletions packages/core/dist/hongkong.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
code, name, province, city, area
810001,中西区,81,00,01
810002,湾仔区,81,00,02
810003,东区,81,00,03
810004,南区,81,00,04
810005,油尖旺区,81,00,05
810006,深水埗区,81,00,06
810007,九龙城区,81,00,07
810008,黄大仙区,81,00,08
810009,观塘区,81,00,09
810010,荃湾区,81,00,10
810011,屯门区,81,00,11
810012,元朗区,81,00,12
810013,北区,81,00,13
810014,大埔区,81,00,14
810015,西贡区,81,00,15
810016,沙田区,81,00,16
810017,葵青区,81,00,17
810018,离岛区,81,00,18
9 changes: 9 additions & 0 deletions packages/core/dist/macau.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
code, name, province, city, area
820001,花地玛堂区,82,00,01
820002,花王堂区,82,00,02
820003,望德堂区,82,00,03
820004,大堂区,82,00,04
820005,风顺堂区,82,00,05
820006,嘉模堂区,82,00,06
820007,路凼填海区,82,00,07
820008,圣方济各堂区,82,00,08
18 changes: 17 additions & 1 deletion packages/core/script/hongkong-macau.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ require('superagent-charset')(request);
await fs.writeFile('./dist/hongkong.json', JSON.stringify(data, null, 2));
console.log(' \x1b[32;1m✔\x1b[0m 获取香港 <区> 数据: ./dist/hongkong.json');

// -----> 保存 hongkong.csv 数据
let csvData = 'code, name, province, city, area\n';
[...data].forEach(dt => {
csvData += ['code', 'name', 'province', 'city', 'area'].map(name => dt[name] || '').join(',') + '\n';
});
await fs.outputFile('./dist/hongkong.csv', csvData.replace(/\n$/, ''));
console.log(' \x1b[32;1m✔\x1b[0m 生成香港 <区> CSV 数据: ./dist/hongkong.csv');

data = [];
const resultMacau = await request.get(macauurl).buffer(true);
if (resultMacau.statusCode !== 200 || !resultMacau.body || !Array.isArray(resultMacau.body.features)) {
Expand All @@ -52,7 +60,15 @@ require('superagent-charset')(request);
}
})
await fs.writeFile('./dist/macau.json', JSON.stringify(data, null, 2));
console.log(' \x1b[32;1m✔\x1b[0m 获取香港 <区> 数据: ./dist/macau.json');
console.log(' \x1b[32;1m✔\x1b[0m 获取澳门 <区> 数据: ./dist/macau.json');

// -----> 保存 macau.csv 数据
csvData = 'code, name, province, city, area\n';
[...data].forEach(dt => {
csvData += ['code', 'name', 'province', 'city', 'area'].map(name => dt[name] || '').join(',') + '\n';
});
await fs.outputFile('./dist/macau.csv', csvData.replace(/\n$/, ''));
console.log(' \x1b[32;1m✔\x1b[0m 生成澳门 <区> CSV 数据: ./dist/macau.csv');

} catch (error) {
console.log(`ERR:获取<香港>数据[]:`, error);
Expand Down

0 comments on commit c28c3e9

Please sign in to comment.