Weather query based on API interface provided by China Meteorological Bureau

Source: Internet
Author: User
Tags comparison table

The China Meteorological Bureau provides three API interfaces for weather queries:

"1" http://www.weather.com.cn/data/sk/101190101. html

"2" http://www.weather.com.cn/data/cityinfo/101190101. html

"3" http://m.weather.com.cn/data/101190101. html

Returns data in JSON format, the first and second interfaces return real-time weather data for the current day, and a third returns the weather for the next five days.

The numbers in the address indicate the city's code: 101190101 for Nanjing (the method to get the city code is explained below)

An example of the return data for the third interface is described below:

  1. {
  2. Weatherinfo: {
  3. City: "Nanjing",
  4. City_en: "Nanjing",
  5. Date_y: "September 8, 2013",
  6. Date: " ",
  7. Week: "Sunday",
  8. Fchh: "",
  9. Cityid: "101190101", //city Code
  10. Temp1: "22℃~30℃", //First day (day) maximum drinking minimum temperature (Celsius temperature)
  11. Temp2: "23℃~29℃", //next day highest drinking minimum temperature (Celsius temperature)
  12. Temp3: "22℃~28℃", //third day maximum drinking minimum temperature (Celsius temperature)
  13. Temp4: "23℃~30℃", //fourth day maximum drinking minimum temperature (Celsius temperature)
  14. TEMP5: "24℃~28℃", //fifth day maximum drinking minimum temperature (Celsius temperature)
  15. TEMP6: "23℃~28℃", //sixth day maximum drinking minimum temperature (Celsius temperature)
  16. TempF1: "71.6℉~86℉", //First day (day) maximum drink minimum temperature (Fahrenheit temperature)
  17. TempF2: "73.4℉~84.2℉", //The next day maximum drinking minimum temperature (Fahrenheit temperature)
  18. TempF3: "71.6℉~82.4℉", //third day maximum drinking minimum temperature (Fahrenheit temperature)
  19. TempF4: "73.4℉~86℉", //fourth day maximum drink minimum temperature (Fahrenheit temperature)
  20. TempF5: "75.2℉~82.4℉", //fifth day maximum drink minimum temperature (Fahrenheit temperature)
  21. TempF6: "73.4℉~82.4℉", //sixth day maximum drink minimum temperature (Fahrenheit temperature)
  22. Weather1: "Cloudy", //First day (day) weather
  23. Weather2: "Light Rain", //Next day weather
  24. Weather3: "drizzle",
  25. Weather4: "Yin",
  26. WEATHER5: "Light rain turns to cloudy",
  27. WEATHER6: "moderate rain turns yin",
  28. IMG1: "1", //Weather Picture Code 1 for the first day
  29. Img2: "2", //Weather Picture Code 2 for the first day
  30. IMG3: "7", //weather image for the next day code 1
  31. IMG4: "The next day" Weather image code 2
  32. IMG5: "7",
  33. Img6: " the",
  34. Img7: "2",
  35. Img8: " the",
  36. IMG9: "7",
  37. IMG10: "8",
  38. IMG11: "8",
  39. Img12: "2",
  40. Img_single: "2"
  41. Img_title1: "Cloudy", //First day weather picture 1 title
  42. Img_title2: "Yin", //The first day of the weather Picture 2 title
  43. Img_title3: "drizzle", //The next day weather picture 1 title
  44. Img_title4: "drizzle", //The next day weather Picture 2 title
  45. Img_title5: "drizzle",
  46. Img_title6: "drizzle",
  47. Img_title7: "Yin",
  48. Img_title8: "Yin",
  49. Img_title9: "drizzle",
  50. Img_title10: "Moderate rain",
  51. IMG_TITLE11: "Moderate rain",
  52. Img_title12: "Yin",
  53. Img_title_single: "Yin",
  54. Wind1: "Dongfeng level 3-4", //First day wind direction range
  55. Wind2: "Dongfeng level 3-4", ///second day wind direction range
  56. Wind3: "North wind turn to northeast 3-4",
  57. Wind4: "3-4 levels Northeast",
  58. Wind5: "The northeast winds turn to the westerly level 3-4",
  59. Wind6: "West wind turn westerly 3-4",
  60. FX1: "Dongfeng",
  61. FX2: "Dongfeng",
  62. FL1: "Level 3-4", //First day wind range
  63. FL2: "Level 3-4",
  64. FL3: "Level 3-4",
  65. FL4: "Level 3-4",
  66. FL5: "Level 3-4",
  67. FL6: "Level 3-4",
  68. Index: "hot", //24-hour dressing index
  69. Index_d: "hot weather, it is recommended that short skirts, shorts, thin jackets, t-shirts and other summer clothing." ", //Suggest
  70. index48: "hot", //48-hour dressing index
  71. Index48_d: "hot weather, it is recommended that short skirts, shorts, thin jackets, t-shirts and other summer clothing." ", //Suggest
  72. INDEX_UV: "Weak", //24 hours UV
  73. INDEX48_UV: "Weak", //48 hours UV
  74. INDEX_XC: "not suitable", //car wash
  75. INDEX_TR: "fit", //Travel
  76. Index_co: "more comfortable", //Comfort
  77. ST1: "a",
  78. ST2: "a",
  79. ST3: "qi",
  80. ST4: "+",
  81. ST5: "+",
  82. ST6: "",
  83. INDEX_CL: "more suitable", //morning exercise
  84. Index_ls: "not very suitable", //drying
  85. Index_ag: "very easy Hair" //Allergy
  86. }
  87. }

Ways to get City code:

1. Get a list of provinces first

Http://www.weather.com.cn/data/city3jdata/china.html

This link returns an array containing the province code and the province name in JSON format

    1. {
    2. 10101: "Beijing",
    3. 10102: "Shanghai",
    4. ....   ,
    5. 10119: "Jiangsu",
    6. }

2. Get a list of cities by the province code obtained above:

such as Jiangsu City Code is: 10119, through the following link to get a list of cities in Jiangsu Province

Http://www.weather.com.cn/data/city3jdata/provshi/10119.html

    1. {
    2. : "Lianyungang",
    3. One: "Changzhou",
    4. ...
    5. 01: "Nanjing",
    6. }

3. Get the regional information under the city

To get the city code from the previous step, such as: Nanjing is 01

01 received the first step to obtain the province code after obtaining 1011901 representative of Nanjing City, Jiangsu Province

Use the link below to get the region information for Nanjing, Jiangsu Province, and add the bold part to the code you just generated

http://www.weather.com.cn/data/city3jdata/station/1011901. html

    1. {
    2. "Nanjing",
    3. : "Lishui",
    4. "Gaochun",
    5. Note: "Jiangning",
    6. A: "Liuhe",
    7. : "Jiangpu",
    8. : "Pukou"
    9. }

4. Get the area code

The area code obtained above is as follows: (on behalf of Nanjing area) received the third step of Jiangsu province Nanjing code 1011901

Get 101190101 representative of Jiangsu province Nanjing Nanjing City Code.

This string of code is what we need.

http://m.weather.com.cn/data/101190101. html

Put it in this link and we can get the weather information of Nanjing City, Jiangsu province Nanjing!

Below is a SQL file that provides a demo address and a city Code comparison table for the Weather query tool I have written.

Weather query based on API interface provided by China Meteorological Bureau

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.