Sha256: d1b04be67dcb4c3475d5e12b6ffc977d32c609c5350dcc59981806de36fda97d

Contents?: true

Size: 1.41 KB

Versions: 119

Compression:

Stored size: 1.41 KB

Contents

require 'date'
require_relative 'base_client'

class AdopsReportScrapper::MarfeelClient < AdopsReportScrapper::BaseClient
  private

  def login
    @client.visit 'https://insight.marfeel.com/hub/login'
    @client.fill_in 'j_username', :with => @login
    @client.fill_in 'Password', :with => @secret
    @client.click_button 'Login'
    begin
      @client.find :xpath, '//*[text()="REPORTING"]'
    rescue Exception => e
      raise e, 'Marfeel login error'
    end
  end

  def scrap
    request_report
    extract_data_from_report
  end

  def request_report
    @client.visit 'https://insight.marfeel.com/hub/insight/reporting?date=1d'
    sleep 1
  end

  def extract_data_from_report
    rows = @client.find_all :xpath, '//table/*/tr'
    n_rows = rows.map do |tr|
      tr.find_css('td,th').map do |td|
        datum = td.visible_text
        if datum.end_with? ' K'
          datum = datum.to_f * 1_000
        elsif datum.end_with? ' M'
          datum = datum.to_f * 1_000_000
        end
        datum.to_s
      end
    end
    n_rows[0][0] = 'Site'
    site = nil
    l = n_rows[0].count
    @data = n_rows.map do |row|
      if row.count == l
        row[0] = row[0].split(' $')[0]
        site = row[0]
      else
        row.unshift site
      end
      row
    end
    (@data.count - 1).times do |i|
      i.even? ? @data[i+1].unshift('Smartphone') : @data[i+1].unshift('Tablet')
    end
    @data[0].unshift 'Device'
  end
end

Version data entries

119 entries across 119 versions & 1 rubygems

Version Path
adops_report_scrapper-0.1.38 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.37 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.36 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.35 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.34 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.33 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.32 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.31 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.30 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.29 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.28 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.27 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.26 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.25 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.24 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.23 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.22 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.21 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.20 lib/adops_report_scrapper/marfeel_client.rb
adops_report_scrapper-0.1.19 lib/adops_report_scrapper/marfeel_client.rb