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 +4 -4
- data/CHANGELOG +3 -0
- data/Rakefile +5 -0
- data/lib/adops_report_scrapper/adsparc_client.rb +62 -0
- data/lib/adops_report_scrapper/version.rb +1 -1
- data/lib/adops_report_scrapper.rb +1 -0
- data/secret.sample.yml +3 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98a0c77cfd9e06624bf5994f7cc64a4833987e04
|
4
|
+
data.tar.gz: 695e54b633e13adafe601bd7a6edb22fd482253b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59c9a0041d61d1957e9a8cf6ad2cc91d022382d7ba067138b2aa59ba5685ae5c23f983e64be6efcf8c3a6047ca26f1d0e6a8298ac875eeb56a8895f76f96efe1
|
7
|
+
data.tar.gz: d152000831ee7a2e83072f112b1889b67a91249ca8fd652874d138efd46dbde3832434796154ebabc0a60ee11e40eff51d78de939e0c6ea0f46fb758a6b13282
|
data/CHANGELOG
CHANGED
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
|
data/secret.sample.yml
CHANGED
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.
|
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
|