adops_report_scrapper 0.1.65 → 0.1.66

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: 3d27c37373f72fa370e6d798e0c3c26bab9f18cc
4
- data.tar.gz: 0b7f49fc44cbaae730423e6b21aef0bd821aac4f
3
+ metadata.gz: 93a875311b6b77e868a4afb1498b6b4cb4e41d37
4
+ data.tar.gz: 05efa95ce31b91d04962cb27083983f43961de43
5
5
  SHA512:
6
- metadata.gz: 83a8955ca204622903146bece36c436531cb029faf91053a33904afd318428a14b77e3299545b195eed8bb1cbf77a106b4a9a0383c487cd25af75a75e2c161c9
7
- data.tar.gz: 5d1f0e254e9416803232a2af373c315528755ce0f01c4b759386facd0e32d86fc6199699d53c1c91fa732c3bfcdb75dfc25a4cdf53a623ac7c0c1b91716d7eb3
6
+ metadata.gz: bc4a06bcf1164aa5ad813820c574fe791474fee52f19f7626229018478807eb10d7397979fbf76c8a6a94b383d9f6a4a1647d64863854c11f9402ba14e7dbea9
7
+ data.tar.gz: 60e9ab3f00ff30bec0f3a652d18bfe2287d563b3b13c570d7288f56ef5e21f2e05268a35e68949e7e6f069b175033157291736ff74e46727391f48c9aa7fd216
data/CHANGELOG CHANGED
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.1.66
4
+ implement gumgum
5
+
3
6
  ## 0.1.65
4
7
  fix brightroll
5
8
 
data/Rakefile CHANGED
@@ -186,6 +186,11 @@ task :sovrn do
186
186
  save_as_csv :sovrn, :sovrn
187
187
  end
188
188
 
189
+ desc 'Collect gumgum data'
190
+ task :gumgum do
191
+ save_as_csv :gumgum, :gumgum
192
+ end
193
+
189
194
  def date
190
195
  @date ||= ENV['date'].nil? ? Date.today - 1 : Date.today - ENV['date'].to_i
191
196
  end
@@ -48,3 +48,4 @@ require 'adops_report_scrapper/positivemobile_client'
48
48
  require 'adops_report_scrapper/brightcom_client'
49
49
  require 'adops_report_scrapper/appnexus_client'
50
50
  require 'adops_report_scrapper/sovrn_client'
51
+ require 'adops_report_scrapper/gumgum_client'
@@ -0,0 +1,81 @@
1
+ require 'date'
2
+ require_relative 'base_client'
3
+
4
+ class AdopsReportScrapper::GumgumClient < AdopsReportScrapper::BaseClient
5
+ def date_supported?(date = nil)
6
+ _date = date || @date
7
+ return true if _date >= Date.today - 7
8
+ false
9
+ end
10
+
11
+ private
12
+
13
+ def init_client
14
+ fail 'please specify gumgum product. e.g. in_image' unless @options['product']
15
+ @product = @options['product']
16
+ super
17
+ end
18
+
19
+ def login
20
+ @client.visit 'https://app.gumgum.com/login'
21
+ @client.fill_in 'Email', :with => @login
22
+ @client.fill_in 'Password', :with => @secret
23
+ @client.click_button 'Login'
24
+ begin
25
+ @client.find :xpath, '//*[text()="Reporting"]'
26
+ rescue Exception => e
27
+ raise e, 'Gumgum login error'
28
+ end
29
+ cookies = @client.driver.cookies
30
+ @client = HTTPClient.new
31
+ @client.cookie_manager.cookies = cookies.values.map do |cookie|
32
+ cookie = cookie.instance_variable_get(:@attributes)
33
+ HTTP::Cookie.new cookie
34
+ end
35
+ end
36
+
37
+ def scrap
38
+ @date_str = @date.strftime('%Y-%m-%d')
39
+ all_desktop_rows = get_parsed_report('ALL', '1')
40
+ all_mobile_rows = get_parsed_report('ALL', '2')
41
+ all_tablet_rows = get_parsed_report('ALL', '14')
42
+ us_desktop_rows = get_parsed_report('US', '1')
43
+ us_mobile_rows = get_parsed_report('US', '2')
44
+ us_tablet_rows = get_parsed_report('US', '14')
45
+ intl_desktop_rows = deduct_data_by_tracking_id(all_desktop_rows, us_desktop_rows)
46
+ intl_mobile_rows = deduct_data_by_tracking_id(all_mobile_rows, us_mobile_rows)
47
+ intl_tablet_rows = deduct_data_by_tracking_id(all_tablet_rows, us_tablet_rows)
48
+
49
+ @data = [['day', 'zoneName', 'trackingId', 'inventoryImpressions', 'adImpressions', 'earnings', 'country', 'browser']]
50
+ @data.concat(us_desktop_rows.map { |row| row.concat(['us', 'desktop']) })
51
+ @data.concat(us_mobile_rows.map { |row| row.concat(['us', 'mobile']) })
52
+ @data.concat(us_tablet_rows.map { |row| row.concat(['us', 'tablet']) })
53
+ @data.concat(intl_desktop_rows.map { |row| row.concat(['intl', 'desktop']) })
54
+ @data.concat(intl_mobile_rows.map { |row| row.concat(['intl', 'mobile']) })
55
+ @data.concat(intl_tablet_rows.map { |row| row.concat(['intl', 'tablet']) })
56
+ end
57
+
58
+ def get_parsed_report(country, brwoser)
59
+ response = @client.get("https://app.gumgum.com/p/reports/widget/table/metric/earnings/units/PRODUCT/target/#{@product}/start/#{@date_str}/end/#{@date_str}/zones/ALL/country/#{country}/browser/#{brwoser}/format/get.json")
60
+ return JSON.parse(response.body)['rows'].map do |row|
61
+ mapped_row = row.values_at(0, 1, 2, 3, 4, -1).map { |item| item['f'] }
62
+ mapped_row[3] = mapped_row[3].to_i
63
+ mapped_row[4] = mapped_row[4].to_i
64
+ mapped_row[5] = mapped_row[5].to_f
65
+ mapped_row
66
+ end
67
+ end
68
+
69
+ def deduct_data_by_tracking_id(rows_to_deduct, rows_deduct_by)
70
+ rows_to_return = rows_to_deduct.dup
71
+ rows_to_return.map do |row_to_return|
72
+ row_deduct_by = rows_deduct_by.select { |row_deduct_by| row_deduct_by[2] == row_to_return[2] }
73
+ return row_to_return if row_deduct_by.empty?
74
+ row_deduct_by = row_deduct_by[0]
75
+ row_to_return[3] = row_to_return[3] - row_deduct_by[3]
76
+ row_to_return[4] = row_to_return[4] - row_deduct_by[4]
77
+ row_to_return[5] = row_to_return[5] - row_deduct_by[5]
78
+ row_to_return
79
+ end
80
+ end
81
+ end
@@ -1,3 +1,3 @@
1
1
  module AdopsReportScrapper
2
- VERSION = "0.1.65"
2
+ VERSION = "0.1.66"
3
3
  end
data/secret.sample.yml CHANGED
@@ -123,3 +123,8 @@ appnexus:
123
123
  sovrn:
124
124
  login: ------
125
125
  secret: ------
126
+ gumgum:
127
+ login: ------
128
+ secret: ------
129
+ options:
130
+ product: ------
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.65
4
+ version: 0.1.66
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-03-10 00:00:00.000000000 Z
11
+ date: 2017-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -235,6 +235,7 @@ files:
235
235
  - lib/adops_report_scrapper/criteo_client.rb
236
236
  - lib/adops_report_scrapper/facebookaudience_client.rb
237
237
  - lib/adops_report_scrapper/gcs_client.rb
238
+ - lib/adops_report_scrapper/gumgum_client.rb
238
239
  - lib/adops_report_scrapper/imonomy_client.rb
239
240
  - lib/adops_report_scrapper/littlethings_client.rb
240
241
  - lib/adops_report_scrapper/liveintent_client.rb