npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

weathercityid

v0.0.3

Published

中国行政区编码和天气api城市编码

Downloads

3

Readme

中国行政区域数据+天气api的城市编号/China administrative area data + weather api city code

简介

本项目适用于调用中国天气网api的城市参数转换,也可用于为城市选择级联组件提供数据.项目包含原始中国行政区数据集data.js,cityNameWeatherId.js,以及项目构建测试代码.项目最终以根目录下的index.js和index.d.ts为主题,其余为相关代码. 使用城市编码查询相关信息,相对于使用城市名,行政区编码,ip等方式,有着避免重复,划分粒度合理,格式规范准确等优势. 虽然中国天气网不再更新数据,但是国内现存的天气服务API大都支持中国天气网的API规范.所以此项目仍然有其存在的意义.

标准

const data = {
  // ...
  "330000": {
      "330100": {
        "cityName": "杭州市",
        "unofficialCityName": "杭州",
        "weatherId": 101210101
      },
      // ...
  },
  // ...
}

|属性名|类型|意义| |---|---|---| |cityName|string|城市名| |unofficialCityName|string|城市名| |weatherId|number|对应中国天气网api中的area|

用法

//ES6 Module
import weatherCityId form "weatherCityId"
//Common Module
const weatherCityId = reqriue("weatherCityId")


console.log(weatherCity["86"]["110000"])

for (const key in weatherCity) {
  for (const index in weatherCity[key]) {
    let cityItem = weatherCity[key][index]
    console.log(cityItem.cityName, cityItem.unofficialCityName, cityItem.weatherId)
  }
}

构建方法

  1. 数据准备阶段

    中国行政区数据来自china-area-data

    weatherCityId来自中国天气网

  2. pretreat阶段

    pretreat文件夹里是对相关数据的预处理脚本,主要为了筛选重复数据,筛选城市名中带有少数民族名称,及相关数据的统计,格式转换

  3. build阶段

    src文件夹的build.js为主要功能脚本 data.js为原始行政区数据 cityNameWeatherId.js 为weatherCityId相关数据 cityNameWeatherIdPolyfill.js 为weatherCityId重复名称以及例外数据 minoritySet.js为少数民族名称数据

  4. 人工审查阶段

    配合test文件夹做测试,然后执行 node ./src/build.js生成数据到dist,文件名为index.json 人工粗略审查

  5. 发布

注意

由于行政区编号和城市天气代码不是绝对一一对照关系,可能存在多个行政区对应一个天气编码的情况

由于地名重名等原因,即使做了漏洞修补也可能造成极少数小城市对应的城市编码错误,如发现请issue反馈

由于少数民族地区城市名称极其复杂所以少数民族地区的unofficialCityName仅供参考,实际以官方行政区名称为准

港澳地区面积过小,特别行政区内的大多数市区可能使用香港,澳门的城市编码代替

历史版本

  • ✅v0.0.1 发布weatherCityId包,实现基本功能
  • ✅v0.0.2 修复部分bug,修复单字城市名称,修复大部分少数民族城市名的简写形式
  • ✅v0.0.3 重构项目构建脚本src/build.js,一键重新构建
  • 🟩v0.0.X 添加更多支持,优化算法,修复潜在BUG