mango_china_city 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a9aee32f3a13c56565ddb4b5feac7338c30c6f28d29095b92770dfb1d21316c
4
- data.tar.gz: 4640404eede191107fe4ad8940d6f16a915f3966b3543aa85cfb857f2b48fb12
3
+ metadata.gz: 6b6c28172c75915fa60caabb3d1102bcd540729b75819e197e2e728ba4ef9715
4
+ data.tar.gz: 5417adf2b8560680f8a5d2c58ca8f20988e403079ad711d85d74fe516c657732
5
5
  SHA512:
6
- metadata.gz: c5765e2247e3a0352a934f33adec28c9ae039be6ee25cbef4332014a8b58074bce480178e7fa29f9f82392400650285efe6691ace4c33aecbfaccc0febc0f24a
7
- data.tar.gz: ea24d4f1063f4796b84673241576fbd7250702e0873b408dd6ab60e430fb6d47ba020ba460afdf2cd47a1b810bb302a7e2967d4612c8f8e94813df414dae611b
6
+ metadata.gz: 70597e605d100886ce09788aee8799d6ff10723ee000397b5ece06e3f6e2555a9a482e49a5a84784554c3d2e985b8021a0cc14cbc3e94191e33bc70239a9b4d2
7
+ data.tar.gz: 7c24ab2d35ce3944affdf248c2e7fa820b9dc0cbb326c0b838f31ddead1572521175aaa4fc1540d7a66109e3dbc6537b340d518d9d8923c3a279f4044d619fed
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MangoChinaCity
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -13,21 +13,27 @@ module MangoChinaCity
13
13
  json = { province: [] }
14
14
  base_url = "http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2020/"
15
15
 
16
- province_res = convert_utf8( RestClient.get("#{base_url}index.html").body )
16
+ province_res = convert_utf8(
17
+ (RestClient::Request.execute(method: :get, url: "#{base_url}index.html", timeout: 1).body rescue retry)
18
+ )
17
19
  province_res.match(/<td>.+<\/td>/).to_s.gsub(/<br\/>|<\/td>|<td>/,'').split("</a>").each do |province|
18
20
  # p_url省详情的页面地址, code 省code
19
21
  p_url, code = province.match(/(\d+).html/).to_a
20
22
  province_ = { name: province.match(/[\u4e00-\u9fa5]+/).to_s, code: "#{code}", city: []}
21
23
  puts "正在同步#{province.match(/[\u4e00-\u9fa5]+/).to_s}"
22
24
  # 获取省下的市
23
- city_res = convert_utf8( RestClient.get("#{base_url}#{p_url}").body )
25
+ city_res = convert_utf8(
26
+ (RestClient::Request.execute(method: :get, url: "#{base_url}#{p_url}", timeout: 1).body rescue retry)
27
+ )
24
28
 
25
29
  city_res.gsub(/\r|\n/,'').match(/<a href=.+<\/a>/).to_s.split("</tr>").each do |city|
26
30
  c_url, c_code = city.match(/(\d+).html/).to_a
27
31
  city_ = { name: city.match(/[\u4e00-\u9fa5]+/).to_s, code: "#{c_code}", district: [] }
28
32
  puts "正在同步#{province.match(/[\u4e00-\u9fa5]+/).to_s}::#{city.match(/[\u4e00-\u9fa5]+/).to_s}"
29
33
  # 获取市下的区
30
- district_res = convert_utf8( RestClient.get("#{base_url}#{code}/#{c_url}").body )
34
+ district_res = convert_utf8(
35
+ (RestClient::Request.execute(method: :get, url: "#{base_url}#{code}/#{c_url}", timeout: 1).body rescue retry)
36
+ )
31
37
  district_res.gsub(/\r|\n/,'').match(/<a href=.+<\/a>/).to_s.split("</tr>").each do |district|
32
38
  d_url, d_code = district.match(/(\d+).html/).to_a
33
39
  city_[:district] << { name: district.match(/[\u4e00-\u9fa5]+/).to_s, code: d_code }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mango_china_city
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - 刘琦
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-02 00:00:00.000000000 Z
11
+ date: 2021-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails