adops_report_scrapper 0.1.60 → 0.1.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +3 -0
- data/Rakefile +6 -1
- data/lib/adops_report_scrapper.rb +1 -0
- data/lib/adops_report_scrapper/appnexus_client.rb +41 -0
- data/lib/adops_report_scrapper/version.rb +1 -1
- 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: 69824afd48c63b45650950d184a9713ebeae951e
|
|
4
|
+
data.tar.gz: 9aa1dee3f08d42f7430cd7dfce42e8e467565850
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a8ba97f5ba81deb3869efde99d9cbdc691c05a26f1772c3f13dc09865e8d4c05e937df391561fb6e004c6a7e457c4608a4456746c14ee530a170a0c3411b64e8
|
|
7
|
+
data.tar.gz: 1c6bd33c7e073b9a5876cb417ae4f03af7aa5d0e854c42c2d408a315a4b3a099e07591b3243ec4e66318621399a50d7aba95a112a581e8ce0eba5e2e3d3c7903
|
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
|
@@ -7,7 +7,7 @@ require 'adops_report_scrapper'
|
|
|
7
7
|
require 'byebug'
|
|
8
8
|
|
|
9
9
|
desc 'Collect all data'
|
|
10
|
-
task :all => [:openx, :tremor, :brightroll, :yellowhammer, :adaptv, :fourninefive, :adx, :revcontent, :gcs, :browsi, :netseer, :sonobi, :nativo, :adsupply, :marfeel, :adsense, :criteo, :triplelift, :conversant, :liveintent, :adiply, :contentad, :facebookaudience, :adtechus, :adtomation, :rhythmone, :littlethings] do # openx is the most unstable one, run it first
|
|
10
|
+
task :all => [:openx, :tremor, :brightroll, :yellowhammer, :adaptv, :fourninefive, :adx, :revcontent, :gcs, :browsi, :netseer, :sonobi, :nativo, :adsupply, :marfeel, :adsense, :criteo, :triplelift, :conversant, :liveintent, :adiply, :contentad, :facebookaudience, :adtechus, :adtomation, :rhythmone, :littlethings, :appnexus] do # openx is the most unstable one, run it first
|
|
11
11
|
puts '========== You are all set'
|
|
12
12
|
end
|
|
13
13
|
|
|
@@ -176,6 +176,11 @@ task :brightcom do
|
|
|
176
176
|
save_as_csv :brightcom, :brightcom
|
|
177
177
|
end
|
|
178
178
|
|
|
179
|
+
desc 'Collect appnexus data'
|
|
180
|
+
task :appnexus do
|
|
181
|
+
save_as_csv :appnexus, :appnexus
|
|
182
|
+
end
|
|
183
|
+
|
|
179
184
|
def date
|
|
180
185
|
@date ||= ENV['date'].nil? ? Date.today - 1 : Date.today - ENV['date'].to_i
|
|
181
186
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
require_relative 'base_client'
|
|
3
|
+
require 'rest-client'
|
|
4
|
+
require 'csv'
|
|
5
|
+
|
|
6
|
+
class AdopsReportScrapper::AppnexusClient < AdopsReportScrapper::BaseClient
|
|
7
|
+
def date_supported?(date = nil)
|
|
8
|
+
_date = date || @date
|
|
9
|
+
return true if _date >= Date.today - 7
|
|
10
|
+
false
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def init_client
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def before_quit_with_error
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def scrap
|
|
22
|
+
date_str = date.strftime '%F'
|
|
23
|
+
|
|
24
|
+
response = RestClient.post 'https://api.appnexus.com/auth', { 'auth' => { 'username' => @login, 'password' => @secret } }.to_json, { content_type: :json, accept: :json }
|
|
25
|
+
response_data = JSON.parse(response.body)
|
|
26
|
+
token = response_data['response']['token']
|
|
27
|
+
|
|
28
|
+
response = RestClient.post 'http://api.appnexus.com/report', { 'report' => { 'report_type' => 'network_analytics', 'report_interval' => 'last_7_days', 'columns' => %w(day publisher_name geo_country supply_type imp_requests imps clicks total_convs revenue) } }.to_json, { content_type: :json, accept: :json, authorization: token }
|
|
29
|
+
response_data = JSON.parse(response.body)
|
|
30
|
+
report_id = response_data['response']['report_id']
|
|
31
|
+
|
|
32
|
+
sleep 10
|
|
33
|
+
|
|
34
|
+
response = RestClient.get "http://api.appnexus.com/report?id=#{report_id}", { authorization: token }
|
|
35
|
+
response_data = JSON.parse(response.body)
|
|
36
|
+
fail 'appnexus report failed' unless response_data['response']['execution_status'] == 'ready'
|
|
37
|
+
|
|
38
|
+
response = RestClient.get "http://api.appnexus.com/report-download?id=#{report_id}", { authorization: token }
|
|
39
|
+
@data = CSV.parse(response.body).select { |row| row[0] == 'day' || (row[0] == date_str && row[4].to_i > 0) }
|
|
40
|
+
end
|
|
41
|
+
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.1.
|
|
4
|
+
version: 0.1.61
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stayman Hou
|
|
@@ -225,6 +225,7 @@ files:
|
|
|
225
225
|
- lib/adops_report_scrapper/adtechus_client.rb
|
|
226
226
|
- lib/adops_report_scrapper/adtomation_client.rb
|
|
227
227
|
- lib/adops_report_scrapper/adx_client.rb
|
|
228
|
+
- lib/adops_report_scrapper/appnexus_client.rb
|
|
228
229
|
- lib/adops_report_scrapper/base_client.rb
|
|
229
230
|
- lib/adops_report_scrapper/brightcom_client.rb
|
|
230
231
|
- lib/adops_report_scrapper/brightroll_client.rb
|