-
Notifications
You must be signed in to change notification settings - Fork 34
/
build-data.js
49 lines (41 loc) · 1.42 KB
/
build-data.js
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
const axios = require('axios')
let pinyin = require('pinyin')
const fs = require('fs')
const request = axios.create({
baseURL: 'https://view.inews.qq.com/g2'
})
function transformChinaData (provinces) {
provinces.forEach(province => {
province.children.forEach(city => {
if (province.name === '北京' || province.name === '上海') {
city.cityName = city.name + '区'
province.pinyin = pinyin(province.name, { style: pinyin.STYLE_NORMAL }).join('')
} else {
if (province.name === '陕西') {
province.pinyin = 'shanxi1'
city.cityName = city.name + '市'
} else if (province.name === '重庆') {
province.pinyin = 'chongqing'
city.cityName = city.name
} else if (province.name === '西藏') {
province.pinyin = 'xizang'
city.cityName = city.name + '市'
} else {
province.pinyin = pinyin(province.name, { style: pinyin.STYLE_NORMAL }).join('')
city.cityName = city.name + '市'
}
}
})
})
// console.log(provinces)
}
function getData () {
request.get('/getOnsInfo?name=disease_h5')
.then(res => {
let rawData = JSON.parse(res.data.data)
let provinces = rawData.areaTree[0].children
transformChinaData (provinces)
fs.writeFileSync('./src/data/area.json', JSON.stringify(rawData))
})
}
getData()