adops_report_scrapper 0.1.0 → 0.1.1

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: 368ff448654fe142f098a05d72c263f4a7c7bacc
4
- data.tar.gz: 8664f20d302251678c328d37401275164476451a
3
+ metadata.gz: 4ed4888eb209682c4179f2320fc0c76dcc9bb266
4
+ data.tar.gz: b4ec13ef9772b23179c18dab0863607387bacb33
5
5
  SHA512:
6
- metadata.gz: 652e2f66cc8326a1e6ebedfd5615f1b0ebaf555c80fd2c8763ac57e69a3e804ca6d2cbd7ed8d3a00b2f59471dd67117c59bc0befd6eb96386758e30eaac3d45e
7
- data.tar.gz: 60ebf84d57a88314c7c922cd445ef943b572e38ba295e6c0e1ba4df100c8ad800eca2377627560898988cd0050fb4df9c8eadddfea12999972d92c2f8ed4325b
6
+ metadata.gz: 3bcc8a0ac2d9b7c01232a5663cd97e0eb06cdd39d1f7d767faa6a9ed6d5e75c30572dfc0abc9cfa2b04362e299521f60092d7ef4d3a4b28aaf392ee8d96bea25
7
+ data.tar.gz: c8056cda55d69c3993de465e19021f948bd81b5ff859ede4564f4322fcc35b9aa638da47d57b67c6a302e92869554fe3978daba32fffaad94dbe94a827250658
data/Rakefile CHANGED
@@ -126,12 +126,16 @@ task :facebookaudience do
126
126
  save_as_csv :facebookaudience, :facebookaudience
127
127
  end
128
128
 
129
+ def date
130
+ @date ||= ENV['date'].nil? ? Date.today - 1 : Date.today - ENV['date'].to_i
131
+ end
132
+
129
133
  def get_yesterdays_file_path(adnetwork)
130
- "tmp/#{Date.today.prev_day}/#{adnetwork}.csv"
134
+ "tmp/#{@date}/#{adnetwork}.csv"
131
135
  end
132
136
 
133
137
  def write_csv(adnet, data)
134
- Dir.mkdir "tmp/#{Date.today.prev_day}" unless Dir.exists? "tmp/#{Date.today.prev_day}"
138
+ Dir.mkdir "tmp/#{@date}" unless Dir.exists? "tmp/#{@date}"
135
139
  CSV.open(get_yesterdays_file_path(adnet), 'w') do |csv|
136
140
  data.each do |row|
137
141
  csv << row
@@ -146,7 +150,6 @@ def save_as_csv(adnet, scrapper) # adnet and scrapper are both sym
146
150
  end
147
151
  puts "========== working on #{adnet}"
148
152
  cred = YAML.load_file('secret.yml')[adnet.to_s]
149
- data = AdopsReportScrapper.get_scrapper(adnet, cred['login'], cred['secret'], cred['options']).get_data
150
- byebug
153
+ data = AdopsReportScrapper.get_scrapper(adnet, cred['login'], cred['secret'], cred['options']).get_data(date)
151
154
  write_csv(adnet, data)
152
155
  end
@@ -3,6 +3,12 @@ require_relative 'base_client'
3
3
  require 'open-uri'
4
4
 
5
5
  class AdopsReportScrapper::BrowsiClient < AdopsReportScrapper::BaseClient
6
+ def date_supported?(date = nil)
7
+ _date = date || @date
8
+ return true if _date >= Date.today - 7
9
+ false
10
+ end
11
+
6
12
  private
7
13
 
8
14
  def login
@@ -4,6 +4,12 @@ require_relative 'base_client'
4
4
  # gcs sometimes doesn't update data in 24 hours
5
5
 
6
6
  class AdopsReportScrapper::GcsClient < 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
+
7
13
  private
8
14
 
9
15
  def login
@@ -1,3 +1,3 @@
1
1
  module AdopsReportScrapper
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stayman Hou