sogou-tuiguang 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 365ea7043202c550e9f85ac5572d72639d934df3
4
- data.tar.gz: f9559b25f786ed370c45f6c1d0b0fb55b2988a56
3
+ metadata.gz: f3e7bbc46dc89507aa68d1c65c514a4e2b99dd31
4
+ data.tar.gz: 651b01ba0a229682211047045ccfd6ebbaed28fd
5
5
  SHA512:
6
- metadata.gz: bf74403d4aea8b7580f521a6f3446d005a180ee82ada3a16d5e35a71d27a988762e0750acd6986cdfcb750ffaacbac4f72ef8c096ba0999de7eef0f00ef63149
7
- data.tar.gz: 6f6d947fa5f71e503a26d650879a735db1733f6207e068b909efff7729573e3dcbb4da115d8c00caee3fade437c42365dfdd1fc7ddd843d7d72b2b22416f197c
6
+ metadata.gz: ccd0d3be9743a8e86c9ce8c7807025343804ddbd084c16b76d4fba66dad9b5fd539a0ae0f5ef48f7cafbed15d6f32f837146401b93e0695c698ece4212161e15
7
+ data.tar.gz: 1866ecb1b56b0cc08f7accbe8b34757261442dd6228c33da9ec0054088eddade72c9a2e84623d89c0ec230b2dd42478b0e5d5297d4524957eecc89b2a6835190
@@ -1,5 +1,5 @@
1
1
  module Sogou
2
2
  module Tuiguang
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -121,14 +121,20 @@ module Sogou
121
121
  request["referer"] = 'http://xuri.p4p.sogou.com/cpcadindex/init.action'
122
122
  request["upgrade-insecure-requests"] = '1'
123
123
  request["user-agent"] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'
124
+ retry_times = 0
124
125
  begin
125
126
  response = http.request(request)
126
127
  if response.is_a?(Net::HTTPRedirection)
127
128
  puts "Redirection: #{response['location']}"
128
129
  raise LoginExpired if response['location'].include? 'https://auth.p4p.sogou.com'
129
130
  end
130
- raise RequestError, "HTTP Response: #{response.code} #{response.message}" unless response.is_a?(Net::HTTPSuccess)
131
- end until response.is_a?(Net::HTTPSuccess)
131
+ unless response.is_a?(Net::HTTPSuccess)
132
+ retry_times += 1
133
+ p 'Sleep 3s'
134
+ sleep 3
135
+ end
136
+ end if !response.is_a?(Net::HTTPSuccess) && retry_times < 10
137
+ raise RequestError, "HTTP Response: #{response.code} #{response.message}" unless response.is_a?(Net::HTTPSuccess)
132
138
  res = response.read_body
133
139
  if response['Content-Encoding'] && response['Content-Encoding'].include?('gzip')
134
140
  res = Zlib::GzipReader.new(StringIO.new(res)).read
@@ -167,12 +173,18 @@ module Sogou
167
173
  request["referer"] = 'http://xuri.p4p.sogou.com/cpcadindex/init.action'
168
174
  request["sogou-request-type"] = 'XMLHTTPRequest'
169
175
  request["user-agent"] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'
176
+ retry_times = 0
170
177
  begin
171
178
  response = http.request(request)
172
179
  raise LoginExpired if response.is_a?(Net::HTTPUnauthorized)
173
180
  puts "Redirection: #{response['location']}" if response.is_a?(Net::HTTPRedirection)
174
- raise RequestError, "HTTP Response: #{response.code} #{response.message}" unless response.is_a?(Net::HTTPSuccess)
175
- end until response.is_a?(Net::HTTPSuccess)
181
+ unless response.is_a?(Net::HTTPSuccess)
182
+ retry_times += 1
183
+ p 'Sleep 3s'
184
+ sleep 3
185
+ end
186
+ end if !response.is_a?(Net::HTTPSuccess) && retry_times < 10
187
+ raise RequestError, "HTTP Response: #{response.code} #{response.message}" unless response.is_a?(Net::HTTPSuccess)
176
188
  @res = response.read_body
177
189
  if response['Content-Encoding'] && response['Content-Encoding'].include?('gzip')
178
190
  @res = Zlib::GzipReader.new(StringIO.new(@res)).read
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sogou-tuiguang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Jie