e360-tuiguang 0.1.6 → 0.1.7
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 +4 -4
- data/lib/e360/tuiguang.rb +51 -27
- data/lib/e360/tuiguang/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdc98be1e89c0a0319d0b93f41738cd6838cf628
|
4
|
+
data.tar.gz: 8b8420fc0e8d9e7d1558f4611c893b949e3feafe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05e4e960d2c87b19e224c9b451f7e49f151e59cf5fda4251a6510640e230a872432e64c1ea98ce6a67461e9f7b4fd1c3cdfb3b0979d965c4027382c2647baeff
|
7
|
+
data.tar.gz: 56b0d0457745fe45cb75dffb5cb1cb7c945b14668ae736d20ddf11659e6dab7ac9670cb02e9781a29448ba0e0118f3e6b171f48469d2ffaf06ae5746e2435254
|
data/lib/e360/tuiguang.rb
CHANGED
@@ -8,12 +8,14 @@ require 'stringio'
|
|
8
8
|
module E360
|
9
9
|
module Tuiguang
|
10
10
|
class Action
|
11
|
-
attr_reader :
|
12
|
-
attr_reader :
|
13
|
-
attr_reader :
|
11
|
+
attr_reader :url
|
12
|
+
attr_reader :params
|
13
|
+
attr_reader :res
|
14
14
|
|
15
15
|
def initialize(cookies)
|
16
16
|
@cookies = cookies
|
17
|
+
@token = nil
|
18
|
+
@expire_times = nil
|
17
19
|
end
|
18
20
|
|
19
21
|
def basic_info
|
@@ -83,8 +85,6 @@ module E360
|
|
83
85
|
next if index < 2
|
84
86
|
|
85
87
|
item = {}
|
86
|
-
#
|
87
|
-
pattern = %r(<input type=checkbox name="check-id" data-gid="(?<group_id>\d+)" data-pid="(?<plan_id>\d+)" data-name="(?<keyword>[^"]+)" data-price="(?<price>[\d\\.]+)" data-left3price="[.\d]+" data-leftprice="[.\d]+" data-minprice="[.\d]+" data-status="" value="(?<keyword_id>\d+)" plan_device="0">.+?<td class="g-status-[^"]+_ f-tal"[^>]*>(?<status>.+?)<a[^>]* data-status="?(?<status_code>-?\d+)"?[^>]*>.+?<td class="(g-status-[^"]+)?_"[^>]*>(?<mobile_status>[\s\S]+?)</td>.+?<td class="effect">\s*<span data-per="?(?<quality_score>-?\d+)"?.+?.+?<td class="effect">\s*<span data-per="?(?<mobile_quality_score>-?\d+)"?.+?<i[^>]* data-match="(?<match>[^"]+)">.+?<i class="b-url [^"]+" data-url="(?<url>[^"]+)">.+?<i class="b-mUrl [^"]+" data-url="(?<mobile_url>[^"]*)")
|
88
88
|
|
89
89
|
%r{<input type=checkbox[^>]* value="(?<id>\d+)"}.match(tr) {|m| item['id'] = m['id']}
|
90
90
|
%r{<input type=checkbox[^>]* data-name="(?<keyword>[^"]+)"}.match(tr) {|m| item['keyword'] = m['keyword']}
|
@@ -119,41 +119,61 @@ module E360
|
|
119
119
|
end
|
120
120
|
|
121
121
|
def keyword_pause(keyword_id)
|
122
|
-
|
123
|
-
result['status'] && result['msg'] == '修改成功'
|
122
|
+
keyword_pause_and_enable(keyword_id)
|
124
123
|
end
|
125
124
|
|
126
125
|
def keyword_enable(keyword_id)
|
127
|
-
|
126
|
+
keyword_pause_and_enable(keyword_id, false)
|
127
|
+
end
|
128
|
+
|
129
|
+
def keywords_pause(keyword_ids = [])
|
130
|
+
keywords_pause_and_enable(keyword_ids)
|
131
|
+
end
|
132
|
+
|
133
|
+
def keywords_enable(keyword_ids = [])
|
134
|
+
keywords_pause_and_enable(keyword_ids, false)
|
135
|
+
end
|
136
|
+
|
137
|
+
def keyword_pause_and_enable(keyword_id, pause = true)
|
138
|
+
result = ajax_request('http://dianjing.e.360.cn/keyword/upstatus', wd: keyword_id, json: 1, status: pause ? -5 : 1)
|
139
|
+
result['status'] && result['msg'] == '修改成功'
|
140
|
+
end
|
141
|
+
|
142
|
+
def keywords_pause_and_enable(keyword_ids = [], pause = true)
|
143
|
+
params = {oper_type: pause ? -5 : 1, json: 1}
|
144
|
+
oper_id = {}
|
145
|
+
keyword_ids.map{|keyword_id| oper_id[keyword_id.to_s] = ''}
|
146
|
+
params[:oper_id] = oper_id.to_json
|
147
|
+
result = ajax_request('http://dianjing.e.360.cn/keyword/upallstatus', params)
|
128
148
|
result['status'] && result['msg'] == '修改成功'
|
129
149
|
end
|
130
150
|
|
131
151
|
def request(url)
|
132
|
-
|
133
|
-
params =
|
152
|
+
uri = URI(url)
|
153
|
+
params = []
|
154
|
+
params = URI.decode_www_form(uri.query) unless uri.query.nil?
|
134
155
|
params.unshift ['_', Time.now.strftime('%s%L')]
|
135
156
|
if @token && @expire_times
|
136
157
|
params.unshift ['expireTimes', @expire_times]
|
137
158
|
params.unshift ['token', @token]
|
138
159
|
end
|
139
|
-
|
140
|
-
@
|
141
|
-
http = Net::HTTP.new(
|
142
|
-
request = Net::HTTP::Get.new(
|
160
|
+
uri.query = URI.encode_www_form(params)
|
161
|
+
@url = uri.to_s
|
162
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
163
|
+
request = Net::HTTP::Get.new(uri)
|
143
164
|
request["accept"] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
|
144
165
|
request["accept-encoding"] = 'gzip, deflate, sdch'
|
145
166
|
request["accept-language"] = 'zh-CN,zh;q=0.8'
|
146
167
|
request["cache-control"] = 'no-cache'
|
147
168
|
request["connection"] = 'keep-alive'
|
148
169
|
request["cookie"] = @cookies
|
149
|
-
request["host"] = 'dianjing.e.360.cn'
|
150
170
|
request["pragma"] = 'no-cache'
|
151
171
|
request["referer"] = "http://dianjing.e.360.cn/adrank?_=#{Time.now.strftime('%s%L')}"
|
152
172
|
request["upgrade-insecure-requests"] = '1'
|
153
173
|
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'
|
154
174
|
retry_times = 0
|
155
175
|
begin
|
156
|
-
puts "Url: #{@
|
176
|
+
puts "Url: #{@url}"
|
157
177
|
response = http.request(request)
|
158
178
|
if response.is_a?(Net::HTTPRedirection)
|
159
179
|
p "Redirection: #{response['location']}"
|
@@ -168,21 +188,25 @@ module E360
|
|
168
188
|
end
|
169
189
|
end if !response.is_a?(Net::HTTPSuccess) && retry_times < 10
|
170
190
|
raise RequestError, "HTTP Response: #{response.code} #{response.message}" unless response.is_a?(Net::HTTPSuccess)
|
171
|
-
@
|
191
|
+
@res = response.read_body
|
172
192
|
if response['Content-Encoding'] && response['Content-Encoding'].include?('gzip')
|
173
|
-
@
|
193
|
+
@res = Zlib::GzipReader.new(StringIO.new(@res)).read
|
174
194
|
end
|
175
|
-
%r("token", *"([^"]+)").match(@
|
195
|
+
%r("token", *"([^"]+)").match(@res) do |tm|
|
176
196
|
@token = tm[1]
|
177
|
-
%r("expireTimes", *"([^"]+)").match(@
|
197
|
+
%r("expireTimes", *"([^"]+)").match(@res) do |etm|
|
178
198
|
@expire_times = etm[1]
|
179
199
|
end
|
180
200
|
end
|
181
|
-
@
|
201
|
+
@res
|
182
202
|
end
|
183
203
|
|
184
204
|
def ajax_request(url, params = {})
|
185
|
-
|
205
|
+
data = params
|
206
|
+
data = params.to_a if params.is_a?(Hash)
|
207
|
+
data << ['token', @token]
|
208
|
+
data << ['expire_times', @expire_times]
|
209
|
+
url = URI(@url = url)
|
186
210
|
http = Net::HTTP.new(url.host, url.port)
|
187
211
|
request = Net::HTTP::Post.new(url)
|
188
212
|
request["accept"] = 'application/json, text/javascript, */*; q=0.01'
|
@@ -201,17 +225,17 @@ module E360
|
|
201
225
|
request["token"] = @token
|
202
226
|
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'
|
203
227
|
request["x-requested-with"] = 'XMLHttpRequest'
|
204
|
-
request.set_form_data(@
|
228
|
+
request.set_form_data(@params = data)
|
205
229
|
response = http.request(request)
|
206
230
|
puts "Redirection: #{response['location']}" if response.is_a?(Net::HTTPRedirection)
|
207
231
|
raise TokenExpired if response.is_a?(Net::HTTPRedirection) && response['location'] == 'http://dianjing.e.360.cn/forbidden/'
|
208
232
|
raise RequestError, "HTTP Response: #{response.code} #{response.message}" unless response.is_a?(Net::HTTPSuccess)
|
209
|
-
@
|
233
|
+
@res = response.read_body
|
210
234
|
if response['Content-Encoding'] && response['Content-Encoding'].include?('gzip')
|
211
|
-
@
|
235
|
+
@res = Zlib::GzipReader.new(StringIO.new(@res)).read
|
212
236
|
end
|
213
|
-
p @
|
214
|
-
JSON.parse(@
|
237
|
+
p @res
|
238
|
+
JSON.parse(@res)
|
215
239
|
end
|
216
240
|
end
|
217
241
|
|