adops_report_scrapper 0.1.36 → 0.1.37

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: 8620e4abb3756a733a39ce5bf308586038c5a6ae
4
- data.tar.gz: 64f4adc907a5e42d7386f78782d8d4c72e72f0d8
3
+ metadata.gz: 4a308286c8be74d32479abae098b6a0c56fe5822
4
+ data.tar.gz: b25af761e68edcbeba8f59f044213159595e945e
5
5
  SHA512:
6
- metadata.gz: b9c25e199d759b37584c8a034d45cfe5e78832946de0f41edd27fbae5a6d7c3a663a95e051b55e7b168314e208025fc254297fbf32e3c387bc617cd6fbf23267
7
- data.tar.gz: 2c5333f175b22d9fb0be6e45225bd38a976e47a2d781ee819920bdcdacce216d3e931c2300498a4be8b9c10f8ff5698051dba0f9b6ba02fae5d5a51fa23fab71
6
+ metadata.gz: 1e3c40e38be7112945dff112f356b382ff73135b103751a27dc9a39994b3c31d8af5ebbed2453eeabdc73cb5cda1d43a2d94f53de286cb79e68d865d514b88c5
7
+ data.tar.gz: c739c40809f150ba8a02ef5d17448e0205ecc4b708d64581fc36ad2e3d5f6b2f96fb644dcf1f329829900e4b53734768afe18a4a301cba35ac1dd496086cf09d
data/CHANGELOG CHANGED
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.1.37
4
+ implement undertone
5
+
3
6
  ## 0.1.35
4
7
  fixed triple lift for their new ui
5
8
 
data/Rakefile CHANGED
@@ -151,6 +151,16 @@ task :littlethings do
151
151
  save_as_csv :littlethings, :littlethings
152
152
  end
153
153
 
154
+ desc 'Collect rubicon data'
155
+ task :rubicon do
156
+ save_as_csv :rubicon, :rubicon
157
+ end
158
+
159
+ desc 'Collect undertone data'
160
+ task :undertone do
161
+ save_as_csv :undertone, :undertone
162
+ end
163
+
154
164
  def date
155
165
  @date ||= ENV['date'].nil? ? Date.today - 1 : Date.today - ENV['date'].to_i
156
166
  end
@@ -41,3 +41,5 @@ require 'adops_report_scrapper/zedo_client'
41
41
  require 'adops_report_scrapper/adtomation_client'
42
42
  require 'adops_report_scrapper/rhythmone_client'
43
43
  require 'adops_report_scrapper/littlethings_client'
44
+ require 'adops_report_scrapper/rubicon_client'
45
+ require 'adops_report_scrapper/undertone_client'
@@ -0,0 +1,43 @@
1
+ require 'date'
2
+ require_relative 'base_client'
3
+ require 'rest-client'
4
+
5
+ class AdopsReportScrapper::RubiconClient < AdopsReportScrapper::BaseClient
6
+ def date_supported?(date = nil)
7
+ _date = date || @date
8
+ return true if _date < Date.today
9
+ false
10
+ end
11
+
12
+ def init_client
13
+ fail 'please specify rubicon account id' unless @options['account_id']
14
+ @account_id = @options['account_id']
15
+ end
16
+
17
+ def before_quit_with_error
18
+ end
19
+
20
+ private
21
+
22
+ def scrap
23
+ tz = date.to_time.dst? ? '-07:00' : '-08:00'
24
+ date_str = date.strftime '%F'
25
+ date_start_str = "#{date_str}T00:00:00#{tz}"
26
+ date_end_str = "#{date_str}T23:59:59#{tz}"
27
+ byebug
28
+
29
+ response = RestClient::Request.execute method: :get, url: 'https://api.rubiconproject.com/analytics/v1/report/', user: @login, password: @secret, account: "publisher/#{@account_id}", start: date_start_str, end: date_end_str, dimensions: ['date'], metrics: ['revenue']
30
+
31
+ date_str = @date.strftime('%-m/%-d/%Y')
32
+ time_zone_id = 'Eastern Standard Time'
33
+
34
+ response = RestClient.post "https://ui.adsupply.com/PublicPortal/Publisher/#{@login}/Report/Export", SqlCommandId: '', ExportToExcel: 'False', IsOLAP: 'False', DateFilter: date_str, TimeZoneId: time_zone_id, Grouping: '1', 'DimPublisher.Value': "#{@login}~", 'DimPublisher.IsActive': 'True', 'DimSiteName.Value': '', 'DimSiteName.IsActive': 'True', 'DimCountry.Value': '', 'DimCountry.IsActive': 'True', 'DimMediaType.Value': '', 'DimMediaType.IsActive': 'True', ApiKey: @secret
35
+
36
+ data = JSON.parse response
37
+ header = data[0].keys
38
+ @data = [header]
39
+ @data += data.map do |datum|
40
+ header.map { |key| datum[key] }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,85 @@
1
+ require 'date'
2
+ require_relative 'base_client'
3
+
4
+ class AdopsReportScrapper::UndertoneClient < AdopsReportScrapper::BaseClient
5
+ def date_supported?(date = nil)
6
+ _date = date || @date
7
+ return true if _date >= Date.today - 3
8
+ false
9
+ end
10
+
11
+ private
12
+
13
+ def login
14
+ @client.visit 'https://insights.undertone.com/user/login'
15
+ @client.fill_in 'user_email', :with => @login
16
+ @client.fill_in 'user_password', :with => @secret
17
+ @client.click_button 'Sign In'
18
+ begin
19
+ @client.find :xpath, '//*[text()="Reporting"]'
20
+ rescue Exception => e
21
+ raise e, 'Undertone login error'
22
+ end
23
+ end
24
+
25
+ def scrap
26
+ request_zone_report
27
+ extract_data_from_zone_report
28
+ request_po_report
29
+ extract_data_from_po_report
30
+ end
31
+
32
+ def request_zone_report
33
+ date_str = date.strftime('%m/%d/%Y')
34
+ @client.fill_in 'start', :with => date_str
35
+ @client.fill_in 'end', :with => date_str
36
+ sleep 2
37
+ @client.select 'Zone Report - Publishers', :from => 'report_id'
38
+ sleep 2
39
+ @client.click_button 'html'
40
+ sleep 10
41
+ end
42
+
43
+ def extract_data_from_zone_report
44
+ @client.within_window @client.driver.browser.window_handles.last do
45
+ @data = []
46
+ rows = @client.find_all :xpath, '//table/*/tr[not(contains(@class, "text"))]'
47
+ rows = rows.to_a
48
+ rows.pop
49
+ @data = rows.map { |tr| tr.find_css('td,th').map { |td| td.visible_text } }
50
+ end
51
+ end
52
+
53
+ def request_po_report
54
+ date_str = date.strftime('%m/%d/%Y')
55
+ @client.fill_in 'start', :with => date_str
56
+ @client.fill_in 'end', :with => date_str
57
+ sleep 2
58
+ @client.select 'Purchase Order Summary', :from => 'report_id'
59
+ sleep 2
60
+ @client.click_button 'html'
61
+ sleep 10
62
+ end
63
+
64
+ def extract_data_from_po_report
65
+ @client.within_window @client.driver.browser.window_handles.last do
66
+ rows = @client.find_all :xpath, '//table/*/tr[not(contains(@class, "text"))]'
67
+ rows = rows.to_a
68
+ rows.pop
69
+ rows.pop
70
+ keys = rows.shift
71
+ keys = keys.find_css('td,th').map { |td| td.visible_text }
72
+ valuess = rows.map { |tr| tr.find_css('td,th').map { |td| td.visible_text } }
73
+ l_data = valuess.map { |values| Hash[keys.zip(values)] }
74
+ @data[0] << 'Revenue'
75
+ l_data.each do |l_datum|
76
+ @data.each_with_index do |datum, i|
77
+ next if i == 0
78
+ next unless datum[0].downcase.tr(' ','').include? "-#{l_datum['Ad Unit'].downcase.tr(' ','')}-"
79
+ @data[i] << datum[3].tr(',','').to_i * l_datum['Sales Price'].tr('USD','').to_f / 1000
80
+ break
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -1,3 +1,3 @@
1
1
  module AdopsReportScrapper
2
- VERSION = "0.1.36"
2
+ VERSION = "0.1.37"
3
3
  end
data/secret.sample.yml CHANGED
@@ -100,3 +100,11 @@ rhythmone:
100
100
  littlethings:
101
101
  login: ------
102
102
  secret: ------
103
+ rubicon:
104
+ login: ------
105
+ secret: ------
106
+ options:
107
+ account_id: ------
108
+ undertone:
109
+ login: ------
110
+ secret: ------
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.36
4
+ version: 0.1.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stayman Hou
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-08 00:00:00.000000000 Z
11
+ date: 2016-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -241,10 +241,12 @@ files:
241
241
  - lib/adops_report_scrapper/openx_client.rb
242
242
  - lib/adops_report_scrapper/revcontent_client.rb
243
243
  - lib/adops_report_scrapper/rhythmone_client.rb
244
+ - lib/adops_report_scrapper/rubicon_client.rb
244
245
  - lib/adops_report_scrapper/sonobi_client.rb
245
246
  - lib/adops_report_scrapper/springserve_client.rb
246
247
  - lib/adops_report_scrapper/tremor_client.rb
247
248
  - lib/adops_report_scrapper/triplelift_client.rb
249
+ - lib/adops_report_scrapper/undertone_client.rb
248
250
  - lib/adops_report_scrapper/version.rb
249
251
  - lib/adops_report_scrapper/zedo_client.rb
250
252
  - secret.sample.yml