adops_report_scrapper 0.2.19 → 0.2.20

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: d23b8a7ecb50b15774fc99b56746d7d2cdaf979b
4
- data.tar.gz: f513b45df43f4e386a0f1af3a3ffa1b09f72afe8
3
+ metadata.gz: 98a0c77cfd9e06624bf5994f7cc64a4833987e04
4
+ data.tar.gz: 695e54b633e13adafe601bd7a6edb22fd482253b
5
5
  SHA512:
6
- metadata.gz: 122c46908bb8a4d9f45958af42292ec8bb14ecab04333b5c9c700be24188f792bdbbe348db224b541b21d2e907b9d172e78e8a1372b641a06d5089c38d37b1a3
7
- data.tar.gz: 9276062bd341293f4808c979caf1ab33f445b34589413ed26ba59a675c8dd57c471fd7ced73902f91529e10936d277b93432dc912447696263b5c874553ad860
6
+ metadata.gz: 59c9a0041d61d1957e9a8cf6ad2cc91d022382d7ba067138b2aa59ba5685ae5c23f983e64be6efcf8c3a6047ca26f1d0e6a8298ac875eeb56a8895f76f96efe1
7
+ data.tar.gz: d152000831ee7a2e83072f112b1889b67a91249ca8fd652874d138efd46dbde3832434796154ebabc0a60ee11e40eff51d78de939e0c6ea0f46fb758a6b13282
data/CHANGELOG CHANGED
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.2.20
4
+ add adsparc
5
+
3
6
  ## 0.2.19
4
7
  fix option logic
5
8
 
data/Rakefile CHANGED
@@ -211,6 +211,11 @@ task :adsupplybuyer do
211
211
  save_as_csv :adsupplybuyer, :adsupplybuyer
212
212
  end
213
213
 
214
+ desc 'Collect adsparc data'
215
+ task :adsparc do
216
+ save_as_csv :adsparc, :adsparc
217
+ end
218
+
214
219
  def date
215
220
  @date ||= ENV['date'].nil? ? Date.today - 1 : Date.today - ENV['date'].to_i
216
221
  end
@@ -0,0 +1,62 @@
1
+ require 'date'
2
+ require_relative 'base_client'
3
+
4
+ class AdopsReportScrapper::AdsparcClient < AdopsReportScrapper::BaseClient
5
+ def date_supported?(date = nil)
6
+ _date = date || @date
7
+ return true if _date >= Date.today - 2
8
+ false
9
+ end
10
+
11
+ private
12
+
13
+ def login
14
+ @client.visit 'http://publisher.adsparc.com/login.php'
15
+ @client.fill_in 'Email', :with => @login
16
+ @client.fill_in 'Password', :with => @secret
17
+ @client.click_button 'Login'
18
+ begin
19
+ @client.find :xpath, '//*[text()="Logout"]'
20
+ rescue Exception => e
21
+ raise e, 'Adsparc login error'
22
+ end
23
+ end
24
+
25
+ def scrap
26
+ request_report
27
+ extract_data_from_report
28
+ end
29
+
30
+ def request_report
31
+ sleep 5
32
+ url = @client.find(:css, '#iframe').base.attributes['src']
33
+ @client.visit url
34
+ sleep 5
35
+ @client.find(:css, '#topCalendar').click
36
+ @client.find(:xpath, '//*[text()="Month to date "]').click
37
+ @client.find(:xpath, '//*[text()="Last 7 Days"]').click
38
+ @client.click_button 'Apply'
39
+ sleep 0.5
40
+ wait_for_loading
41
+ end
42
+
43
+ def extract_data_from_report
44
+ header = @client.find(:xpath, '//*[contains(@class, "widget-item") and .//*[text()="Publisher Earnings Report - by Day"]]//table/thead/tr').find_css('td,th').map { |td| td.visible_text }
45
+ @data = [header]
46
+ date_str = @date.strftime '%d %b %Y'
47
+ rows = @client.find_all(:xpath, "//*[contains(@class, \"widget-item\") and .//*[text()=\"Publisher Earnings Report - by Day\"]]//table/tbody/tr[./td[text()=\"#{date_str}\"]]")
48
+ rows = rows.to_a
49
+ @data.concat(rows.map { |tr| tr.find_css('td,th').map { |td| td.visible_text } })
50
+ end
51
+
52
+ def wait_for_loading
53
+ 30.times do |_i| # wait 5 min
54
+ begin
55
+ @client.find(:xpath, '//*[text()="Day"]')
56
+ break
57
+ rescue Exception => e
58
+ sleep 10
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module AdopsReportScrapper
2
- VERSION = "0.2.19"
2
+ VERSION = "0.2.20"
3
3
  end
@@ -53,3 +53,4 @@ require 'adops_report_scrapper/gumgum_client'
53
53
  require 'adops_report_scrapper/spotxchange_client'
54
54
  require 'adops_report_scrapper/email_client'
55
55
  require 'adops_report_scrapper/anyclip_client'
56
+ require 'adops_report_scrapper/adsparc_client'
data/secret.sample.yml CHANGED
@@ -148,5 +148,8 @@ mediabong:
148
148
  title: XXX Report
149
149
  date_column: 1||%Y-%m-%d
150
150
  anyclip:
151
+ login: ------
152
+ secret: ------
153
+ adsparc:
151
154
  login: ------
152
155
  secret: ------
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adops_report_scrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.19
4
+ version: 0.2.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stayman Hou
@@ -249,6 +249,7 @@ files:
249
249
  - lib/adops_report_scrapper/adforge_client.rb
250
250
  - lib/adops_report_scrapper/adiply_client.rb
251
251
  - lib/adops_report_scrapper/adsense_client.rb
252
+ - lib/adops_report_scrapper/adsparc_client.rb
252
253
  - lib/adops_report_scrapper/adsupply_client.rb
253
254
  - lib/adops_report_scrapper/adsupplybuyer_client.rb
254
255
  - lib/adops_report_scrapper/adtechus_client.rb