adops_report_scrapper 0.1.53 → 0.1.54
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/CHANGELOG +3 -0
- data/Rakefile +5 -0
- data/lib/adops_report_scrapper.rb +1 -0
- data/lib/adops_report_scrapper/brightcom_client.rb +52 -0
- data/lib/adops_report_scrapper/positivemobile_client.rb +2 -4
- data/lib/adops_report_scrapper/version.rb +1 -1
- data/secret.sample.yml +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62e2e15976fbf0aa7daa0441d9de058516ef430d
|
4
|
+
data.tar.gz: 825e99eaa51a577e9e37e0e7560c832330bbedb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b57d8303592a99ed2ab8209aaa8a67b444972535962b1e11d04d17f74c2c52d4210b6f3ef4a4046927b1391fc19a577d84bee06b498761618a6595c25f9d947
|
7
|
+
data.tar.gz: 5053cc3043db4986253bc622235ae25efa042685f3fffd4a0ad976fb467a76f6ff149787ccd669c8a4650ba352d4cd9448fcfac2f04ca570fcb9be109056b021
|
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
@@ -171,6 +171,11 @@ task :positivemobile do
|
|
171
171
|
save_as_csv :positivemobile, :positivemobile
|
172
172
|
end
|
173
173
|
|
174
|
+
desc 'Collect brightcom data'
|
175
|
+
task :brightcom do
|
176
|
+
save_as_csv :brightcom, :brightcom
|
177
|
+
end
|
178
|
+
|
174
179
|
def date
|
175
180
|
@date ||= ENV['date'].nil? ? Date.today - 1 : Date.today - ENV['date'].to_i
|
176
181
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'date'
|
2
|
+
require_relative 'base_client'
|
3
|
+
|
4
|
+
class AdopsReportScrapper::BrightcomClient < AdopsReportScrapper::BaseClient
|
5
|
+
private
|
6
|
+
|
7
|
+
def login
|
8
|
+
@client.visit 'https://compass.brightcom.com/'
|
9
|
+
@client.fill_in 'Username', :with => @login
|
10
|
+
@client.fill_in 'Password', :with => @secret
|
11
|
+
@client.click_button 'Login'
|
12
|
+
sleep 15
|
13
|
+
begin
|
14
|
+
@client.find :xpath, '//*[text()="Reports "]'
|
15
|
+
rescue Exception => e
|
16
|
+
raise e, 'Brightcom login error'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def scrap
|
21
|
+
request_report
|
22
|
+
extract_data_from_report
|
23
|
+
end
|
24
|
+
|
25
|
+
def request_report
|
26
|
+
@client.visit 'https://compass.brightcom.com/onetag/reportsext/display'
|
27
|
+
sleep 5
|
28
|
+
|
29
|
+
group_by_dest_elem = @client.find(:css, '#group_by_dest')
|
30
|
+
@client.find(:xpath, '//div[text()="Tags" and @data-order="1"]').drag_to(group_by_dest_elem)
|
31
|
+
@client.find(:xpath, '//div[text()="Country" and @data-order="2"]').drag_to(group_by_dest_elem)
|
32
|
+
|
33
|
+
metrics_source_elem = @client.find(:css, '#metrics_source')
|
34
|
+
metrics_dest_elem = @client.find(:css, '#metrics_dest')
|
35
|
+
@client.find(:xpath, '//div[text()="Received IMPS" and @data-order="0"]').drag_to(metrics_dest_elem)
|
36
|
+
@client.find(:xpath, '//div[text()="Clicks" and @data-order="3"]').drag_to(metrics_dest_elem)
|
37
|
+
@client.find(:xpath, '//div[text()="Conversion Rate" and @data-order="6"]').drag_to(metrics_source_elem)
|
38
|
+
@client.find(:xpath, '//div[text()="Revenue eCPM" and @data-order="8"]').drag_to(metrics_source_elem)
|
39
|
+
|
40
|
+
@client.click_button 'Run Report'
|
41
|
+
sleep 15
|
42
|
+
end
|
43
|
+
|
44
|
+
def extract_data_from_report
|
45
|
+
rows = @client.find_all(:xpath, '//table[@role="grid"]/tbody/tr')
|
46
|
+
rows = rows.to_a
|
47
|
+
header = @client.find :xpath, '//table[@role="grid"]/thead/tr'
|
48
|
+
n_header = header.find_css('td,th').map { |td| td.visible_text }
|
49
|
+
@data = [n_header]
|
50
|
+
@data += rows.map { |tr| tr.find_css('td,th').map { |td| td.visible_text } }
|
51
|
+
end
|
52
|
+
end
|
@@ -20,8 +20,6 @@ class AdopsReportScrapper::PositivemobileClient < AdopsReportScrapper::BaseClien
|
|
20
20
|
rescue Exception => e
|
21
21
|
raise e, 'Positivemobile login error'
|
22
22
|
end
|
23
|
-
|
24
|
-
|
25
23
|
cookies = @client.driver.cookies
|
26
24
|
@client = HTTPClient.new
|
27
25
|
@client.cookie_manager.cookies = cookies.values.map do |cookie|
|
@@ -39,9 +37,9 @@ class AdopsReportScrapper::PositivemobileClient < AdopsReportScrapper::BaseClien
|
|
39
37
|
date_str = @date.strftime('%Y-%m-%d')
|
40
38
|
|
41
39
|
header = {
|
42
|
-
Accept: '
|
40
|
+
Accept: 'application/json, text/plain, */*',
|
43
41
|
Origin: 'https://rapidv.positivemobile.com',
|
44
|
-
Referer: '
|
42
|
+
Referer: 'https//rapidv.positivemobile.com/reports',
|
45
43
|
'User-Agent': 'Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1',
|
46
44
|
'Content-Type': 'application/json',
|
47
45
|
}
|
data/secret.sample.yml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adops_report_scrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.54
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stayman Hou
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -226,6 +226,7 @@ files:
|
|
226
226
|
- lib/adops_report_scrapper/adtomation_client.rb
|
227
227
|
- lib/adops_report_scrapper/adx_client.rb
|
228
228
|
- lib/adops_report_scrapper/base_client.rb
|
229
|
+
- lib/adops_report_scrapper/brightcom_client.rb
|
229
230
|
- lib/adops_report_scrapper/brightroll_client.rb
|
230
231
|
- lib/adops_report_scrapper/browsi_client.rb
|
231
232
|
- lib/adops_report_scrapper/contentad_client.rb
|