Get the latest China cities data from official site.
Or you can create these data by your own, check out Usage.
- A command line tool
- Get the latest China cities data from Official site
- Outputs format support JSON and CSV
- Option to output first charactors of every word in pinyin as short name of cities, like
BJS
for北京市
- JSON format is compatible with city data of china_city gem
Add this line to your application's Gemfile:
gem 'chinacity'
And then execute:
$ bundle
Or install it yourself as:
$ gem install chinacity
The format is totally compatible with https://github.com/saberma/china_city/blob/master/db/areas.json
$ chinacity > areas.json
The result looks like
{
"province": [
{
"id": "110000",
"text": "北京市"
},
{
"id": "120000",
"text": "天津市"
},
...
],
"city": [
{
"id": "110100",
"text": "市辖区"
},
{
"id": "110200",
"text": "县"
},
...
],
"district": [
{
"id": "110101",
"text": "东城区"
},
{
"id": "110102",
"text": "西城区"
},
...
]
}
$ chinacity -s > areas.json
The result looks like
{
"province": [
{
"id": "110000",
"text": "北京市",
"short": "BJS"
},
{
"id": "120000",
"text": "天津市",
"short": "TJS"
},
{
"id": "130000",
"text": "河北省",
"short": "HBS"
},
...
],
"city": [...],
"district": [...]
}
$ chinacity -sc > areas.csv
The result looks like
id,名称,缩写,层级
110000,北京市,BJS,1
110100,市辖区,SXQ,2
110101,东城区,DCQ,3
110102,西城区,XCQ,3
110105,朝阳区,ZYQ,3
...
$ chinacity --help
Usage: chinacity [options]
options:
-s, --short Short name, first charactors of every word in pinyin
-c, --csv Outputs in CSV format
-m, --minimize Trim spaces to minimize JSON data
-H, --headless Skip outputing the head line for CSV
As chinacity
use csv
library, only Ruby 1.9+ is supported.
- Fork it ( http://github.com//chinacity/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request