adops_report_scrapper 0.2.28 → 0.2.29

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: f9a3c43588406d7cab83467fdf7da34747cd794e
4
- data.tar.gz: 66c4f19f40b9c957178fa0081d9b609c5b5bd333
3
+ metadata.gz: 18fe8a9e5d0db433253503138f2d03cd1adee71b
4
+ data.tar.gz: 73d73a41e74cc15520aae6427901fecdbbae1f73
5
5
  SHA512:
6
- metadata.gz: 01d805112eb0ff90f1d90ed21815bd0bcc3b28b374f525d0e6ebc1e19233726aea8345190873abd228bfe562be7edf18cfaa81f54a8689cd1872d4b64da788b2
7
- data.tar.gz: b52ced1284c164a7bd162d5cf2cf6be807160a1cb2bdedcf020bab9961b8e26315af15923a075b5d559edc732658c22fad8d0daa4028861d32d397a70f96517a
6
+ metadata.gz: e4fc3188f3b828f25b35217569a71e1f368df3f18acfc896f5bd3098889c6b4d25ca38dd31ab998b1acf2eb616e2e78cce6ae989e94522760ac28ebe7c1daec7
7
+ data.tar.gz: 15ff71dd798cd90ee71e83fe632d8c95af18ca418dc750b417090282666af8909fbb4aba5382f807a910dc39fd428c47e86bcb4ecf02d637ca871aa362573d9a
data/CHANGELOG CHANGED
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.2.29
4
+ fix sovrn
5
+
3
6
  ## 0.2.23
4
7
  fix sovrn when hit session expire page before login
5
8
 
@@ -1,5 +1,6 @@
1
1
  require 'date'
2
2
  require_relative 'base_client'
3
+ require 'selenium-webdriver'
3
4
 
4
5
  class AdopsReportScrapper::SovrnClient < AdopsReportScrapper::BaseClient
5
6
  def date_supported?(date = nil)
@@ -8,11 +9,24 @@ class AdopsReportScrapper::SovrnClient < AdopsReportScrapper::BaseClient
8
9
  false
9
10
  end
10
11
 
12
+ def init_client
13
+ Capybara.register_driver :selenium do |app|
14
+ profile = Selenium::WebDriver::Firefox::Profile.new
15
+ @download_dir = '/tmp/sovrn'
16
+ profile['browser.download.dir'] = @download_dir
17
+ clean_up_download_dir
18
+ profile['browser.download.folderList'] = 2
19
+ profile['browser.helperApps.neverAsk.saveToDisk'] = 'application/octet-stream'
20
+ Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
21
+ end
22
+ @client = Capybara::Session.new(:selenium)
23
+ end
24
+
11
25
  private
12
26
 
13
27
  def login
14
28
  @client.visit 'https://meridian.sovrn.com/#welcome'
15
- sleep 5
29
+ sleep 1
16
30
  if @client.find_all(:css, '#user-menu-trigger').count > 0
17
31
  @client.find_all(:css, '#user-menu-trigger').first.click
18
32
  sleep 1
@@ -40,7 +54,6 @@ class AdopsReportScrapper::SovrnClient < AdopsReportScrapper::BaseClient
40
54
 
41
55
  def request_report
42
56
  @client.visit 'https://meridian.sovrn.com/#account/my_downloads'
43
- @client.save_screenshot
44
57
  sleep 5
45
58
  if @client.find_all(:xpath, '//input[@value="domestic_and_international"]').count == 0
46
59
  login
@@ -60,15 +73,14 @@ class AdopsReportScrapper::SovrnClient < AdopsReportScrapper::BaseClient
60
73
  @client.find_all(:xpath, '//button[text()=" Download "]').first.click
61
74
 
62
75
  sleep 2
63
-
64
- url = @client.driver.network_traffic[-1].url
65
- headers = @client.driver.network_traffic[-1].headers
66
-
67
- @response = HTTPClient.get url, header: headers.map{ |header| [header['name'], header['value']] }.to_h
68
76
  end
69
77
 
70
78
  def extract_data_from_report
71
- rows = CSV.parse @response.body
79
+ rows = CSV.parse File.read("#{@download_dir}/adstats_all_traffic.csv")
72
80
  @data = rows[6..-1]
73
81
  end
82
+
83
+ def clean_up_download_dir
84
+ FileUtils.rm_rf(Dir.glob("#{@download_dir}/*"))
85
+ end
74
86
  end
@@ -1,3 +1,3 @@
1
1
  module AdopsReportScrapper
2
- VERSION = "0.2.28"
2
+ VERSION = "0.2.29"
3
3
  end
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.2.28
4
+ version: 0.2.29
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-06-21 00:00:00.000000000 Z
11
+ date: 2017-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient