-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
225 lines (182 loc) · 4.51 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
require 'bundler/gem_tasks'
require 'yaml'
require 'csv'
require 'date'
require 'adops_report_scrapper'
require 'byebug'
desc 'Collect all data'
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, :sovrn, :spotxchange] do # openx is the most unstable one, run it first
puts '========== You are all set'
end
desc 'Collect tremor data'
task :tremor do
save_as_csv :tremor, :tremor
end
desc 'collect brightroll data'
task :brightroll do
save_as_csv :brightroll, :brightroll
end
desc 'Collect yellowhammer data'
task :yellowhammer do
save_as_csv :yellowhammer, :springserve
end
desc 'Collect adaptv data'
task :adaptv do
save_as_csv :adaptv, :adaptv
end
desc 'Collect fourninefive data'
task :fourninefive do
save_as_csv :fourninefive, :adforge
end
desc 'Collect adx data'
task :adx do
save_as_csv :adx, :adx
end
desc 'Collect revcontent data'
task :revcontent do
save_as_csv :revcontent, :revcontent
end
desc 'Collect gcs data'
task :gcs do
save_as_csv :gcs, :gcs
end
desc 'Collect browsi data'
task :browsi do
save_as_csv :browsi, :browsi
end
desc 'Collect openx data'
task :openx do
save_as_csv :openx, :openx
end
desc 'Collect netseer data'
task :netseer do
save_as_csv :netseer, :netseer
end
desc 'Collect sonobi data'
task :sonobi do
save_as_csv :sonobi, :sonobi
end
desc 'Collect nativo data'
task :nativo do
save_as_csv :nativo, :nativo
end
desc 'Collect adsupply data'
task :adsupply do
save_as_csv :adsupply, :adsupply
end
desc 'Collect marfeel data'
task :marfeel do
save_as_csv :marfeel, :marfeel
end
desc 'Collect adsense data'
task :adsense do
save_as_csv :adsense, :adsense
end
desc 'Collect criteo data'
task :criteo do
save_as_csv :criteo, :criteo
end
desc 'Collect triplelift data'
task :triplelift do
save_as_csv :triplelift, :triplelift
end
desc 'Collect conversant data'
task :conversant do
save_as_csv :conversant, :conversant
end
desc 'Collect liveintent data'
task :liveintent do
save_as_csv :liveintent, :liveintent
end
desc 'Collect adiply data'
task :adiply do
save_as_csv :adiply, :adiply
end
desc 'Collect contentad data'
task :contentad do
save_as_csv :contentad, :contentad
end
desc 'Collect facebookaudience data'
task :facebookaudience do
save_as_csv :facebookaudience, :facebookaudience
end
desc 'Collect adtechus data'
task :adtechus do
save_as_csv :adtechus, :adtechus
end
desc 'Collect divisiond data'
task :divisiond do
save_as_csv :divisiond, :zedo
end
desc 'Collect adtomation data'
task :adtomation do
save_as_csv :adtomation, :adtomation
end
desc 'Collect rhythmone data'
task :rhythmone do
save_as_csv :rhythmone, :rhythmone
end
desc 'Collect littlethings data'
task :littlethings do
save_as_csv :littlethings, :littlethings
end
desc 'Collect rubicon data'
task :rubicon do
save_as_csv :rubicon, :rubicon
end
desc 'Collect undertone data'
task :undertone do
save_as_csv :undertone, :undertone
end
desc 'Collect imonomy data'
task :imonomy do
save_as_csv :imonomy, :imonomy
end
desc 'Collect positivemobile data'
task :positivemobile do
save_as_csv :positivemobile, :positivemobile
end
desc 'Collect brightcom data'
task :brightcom do
save_as_csv :brightcom, :brightcom
end
desc 'Collect appnexus data'
task :appnexus do
save_as_csv :appnexus, :appnexus
end
desc 'Collect sovrn data'
task :sovrn do
save_as_csv :sovrn, :sovrn
end
desc 'Collect gumgum data'
task :gumgum do
save_as_csv :gumgum, :gumgum
end
desc 'Collect spotxchange data'
task :spotxchange do
save_as_csv :spotxchange, :spotxchange
end
def date
@date ||= ENV['date'].nil? ? Date.today - 1 : Date.today - ENV['date'].to_i
end
def get_yesterdays_file_path(adnetwork)
"tmp/#{date}/#{adnetwork}.csv"
end
def write_csv(adnet, data)
Dir.mkdir "tmp/#{date}" unless Dir.exists? "tmp/#{date}"
CSV.open(get_yesterdays_file_path(adnet), 'w') do |csv|
data.each do |row|
csv << row
end
end
end
def save_as_csv(adnet, scrapper) # adnet and scrapper are both sym
if File.file?(get_yesterdays_file_path(adnet))
puts "========== #{adnet} data already scraped"
return
end
puts "========== working on #{adnet}"
cred = YAML.load_file('secret.yml')[adnet.to_s]
data = AdopsReportScrapper.get_scrapper(scrapper, cred['login'], cred['secret'], cred['options']).get_data(date)
write_csv(adnet, data)
end