caboose-rets 0.0.5 → 0.0.6
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 +8 -8
- data/app/models/caboose_rets/rets_importer.rb +38 -20
- data/lib/caboose_rets/version.rb +1 -1
- data/lib/tasks/caboose_rets.rake +55 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZjZhMTdjZWFlNmQ0Y2JiYTNhNjhiNmRmM2Q4NTUyYThiNDE0NzZjYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTlhOTIxNjRmMzJkODMzMjVjNzdhMjQyZDNmN2U5YTUzODMyYWEzMg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTg0NGRhNGYxYzg0YTUxNDAyMzVjYmFhODYzYzY2NWE4MmM0MTdkMWRmODcz
|
10
|
+
ZGI0MjFiM2FlYjMxNzllNjYxNWE4NTNlYmVhYWVmMzE5Mjk3NzFlMGI5Nzc3
|
11
|
+
YjU5NWE3ZjQ3N2YxMjIyZTFiMGRmM2RhMWQ0Y2ZkYzljODVmNTk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTg2ZTUyODEzZThhMjNjMDNhMDk3YWMzNTgyMGUxNDdiODc0MTRkMGI3Y2Ey
|
14
|
+
YWE5NWUzMTQyZDkyM2QyMjQ3NzI4YWU2MGEzNjcwZjM0YmI0NzA3ZTVjNGFl
|
15
|
+
ZjgzMTU1YWRhYzUzMDg5ZWI5MjZjNWViZjFiNGE1MDc0YjhmZTI=
|
@@ -94,7 +94,6 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
94
94
|
self.import_modified_after(date_modified, 'Property' , 'LND')
|
95
95
|
self.import_modified_after(date_modified, 'Property' , 'MUL')
|
96
96
|
self.import_modified_after(date_modified, 'Property' , 'RES')
|
97
|
-
self.update_coords
|
98
97
|
end
|
99
98
|
|
100
99
|
def self.update_images_after(date_modified)
|
@@ -167,6 +166,11 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
167
166
|
obj.id = id
|
168
167
|
obj.save
|
169
168
|
end
|
169
|
+
|
170
|
+
case obj
|
171
|
+
when CabooseRets::CommercialProperty, CabooseRets::LandProperty, CabooseRets::MultiFamilyProperty, CabooseRets::ResidentialProperty
|
172
|
+
self.update_coords(obj)
|
173
|
+
end
|
170
174
|
end
|
171
175
|
end
|
172
176
|
|
@@ -198,24 +202,27 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
198
202
|
# Property Images
|
199
203
|
#=============================================================================
|
200
204
|
|
201
|
-
def self.download_property_images_modified_after(date_modified
|
202
|
-
models = [
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
self.download_property_images(p) if found_it
|
205
|
+
def self.download_property_images_modified_after(date_modified)
|
206
|
+
models = [CabooseRets::CommercialProperty, CabooseRets::LandProperty, CabooseRets::MultiFamilyProperty, CabooseRets::ResidentialProperty]
|
207
|
+
names = ["commercial", "land", "multi-family", "residential"]
|
208
|
+
i = 0
|
209
|
+
models.each do |model|
|
210
|
+
count = model.where("photo_date_modified > ?", date_modified.strftime('%FT%T')).count
|
211
|
+
j = 1
|
212
|
+
model.where("photo_date_modified > ?", date_modified.strftime('%FT%T')).reorder(:mls_acct).each do |p|
|
213
|
+
self.log("Downloading images for #{j} of #{count} #{names[i]} properties...")
|
214
|
+
self.download_property_images(p)
|
215
|
+
j = j + 1
|
213
216
|
end
|
217
|
+
i = i + 1
|
214
218
|
end
|
215
219
|
end
|
216
220
|
|
217
221
|
def self.download_property_images(p)
|
218
222
|
self.refresh_property_media(p)
|
223
|
+
|
224
|
+
self.log("-- Downloading images and resizing for #{p.mls_acct}")
|
225
|
+
media = []
|
219
226
|
self.client.get_object(:resource => :Property, :type => :Photo, :location => true, :id => p.id) do |headers, content|
|
220
227
|
|
221
228
|
# Find the associated media record for the image
|
@@ -224,17 +231,24 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
224
231
|
|
225
232
|
if m.nil?
|
226
233
|
self.log("Can't find media record for #{p.mls_acct} #{filename}.")
|
227
|
-
else
|
234
|
+
else
|
228
235
|
m.image = URI.parse(headers['location'])
|
229
|
-
m
|
230
|
-
|
231
|
-
|
236
|
+
media << m
|
237
|
+
#m.save
|
238
|
+
end
|
232
239
|
end
|
240
|
+
|
241
|
+
self.log("-- Uploading images to S3 for #{p.mls_acct}")
|
242
|
+
media.each do |m|
|
243
|
+
m.save
|
244
|
+
end
|
233
245
|
end
|
234
246
|
|
235
247
|
def self.refresh_property_media(p)
|
248
|
+
self.log("-- Deleting images and metadata for #{p.mls_acct}...")
|
236
249
|
CabooseRets::Media.where(:mls_acct => p.mls_acct, :media_type => 'Photo').destroy_all
|
237
250
|
|
251
|
+
self.log("-- Downloading image metadata for #{p.mls_acct}...")
|
238
252
|
params = {
|
239
253
|
:search_type => 'Media',
|
240
254
|
:class => 'GFX',
|
@@ -256,21 +270,25 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
256
270
|
def self.update_coords(p = nil)
|
257
271
|
if p.nil?
|
258
272
|
models = [CabooseRets::CommercialProperty, CabooseRets::LandProperty, CabooseRets::MultiFamilyProperty, CabooseRets::ResidentialProperty]
|
273
|
+
names = ["commercial", "land", "multi-family", "residential"]
|
274
|
+
i = 0
|
259
275
|
models.each do |model|
|
276
|
+
self.log "Updating coords #{names[i]} properties..."
|
260
277
|
model.where(:latitude => nil).reorder(:mls_acct).each do |p|
|
261
278
|
self.update_coords(p)
|
262
279
|
end
|
280
|
+
i = i + 1
|
263
281
|
end
|
264
282
|
return
|
265
283
|
end
|
266
|
-
|
284
|
+
|
285
|
+
self.log "Getting coords for mls_acct #{p.mls_acct}..."
|
267
286
|
coords = self.coords_from_address(CGI::escape "#{p.street_num} #{p.street_name}, #{p.city}, #{p.state} #{p.zip}")
|
268
287
|
return if coords.nil? || coords == false
|
269
288
|
|
270
289
|
p.latitude = coords['lat']
|
271
290
|
p.longitude = coords['lng']
|
272
|
-
p.save
|
273
|
-
self.log "Saved coords for mls_acct #{p.mls_acct}"
|
291
|
+
p.save
|
274
292
|
end
|
275
293
|
|
276
294
|
def self.coords_from_address(address)
|
data/lib/caboose_rets/version.rb
CHANGED
data/lib/tasks/caboose_rets.rake
CHANGED
@@ -15,6 +15,61 @@ namespace :caboose_rets do
|
|
15
15
|
create_multi_family(c)
|
16
16
|
end
|
17
17
|
|
18
|
+
desc "Updates all the listings from MLS"
|
19
|
+
task :update_rets => :environment do
|
20
|
+
if task_is_locked
|
21
|
+
CabooseRets::RetsImporter.log("caboose_rets:update_rets task is locked. Aborting.")
|
22
|
+
next
|
23
|
+
end
|
24
|
+
CabooseRets::RetsImporter.log("Updating rets data...")
|
25
|
+
task_started = lock_task
|
26
|
+
|
27
|
+
begin
|
28
|
+
# RetsImporter.update_all_after(last_updated - Rational(1,86400))
|
29
|
+
CabooseRets::RetsImporter.update_after(last_updated)
|
30
|
+
save_last_updated(task_started)
|
31
|
+
unlock_task
|
32
|
+
rescue
|
33
|
+
raise
|
34
|
+
ensure
|
35
|
+
unlock_task_if_last_updated(task_started)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def last_updated
|
40
|
+
if !Caboose::Setting.exists?(:name => 'rets_last_updated')
|
41
|
+
Caboose::Setting.create(:name => 'rets_last_updated', :value => '2013-08-06T00:00:01')
|
42
|
+
end
|
43
|
+
s = Caboose::Setting.where(:name => 'rets_last_updated').first
|
44
|
+
return DateTime.parse(s.value)
|
45
|
+
end
|
46
|
+
|
47
|
+
def save_last_updated(d)
|
48
|
+
s = Caboose::Setting.where(:name => 'rets_last_updated').first
|
49
|
+
s.value = d.strftime('%FT%T')
|
50
|
+
s.save
|
51
|
+
end
|
52
|
+
|
53
|
+
def task_is_locked
|
54
|
+
return Caboose::Setting.exists?(:name => 'rets_update_running')
|
55
|
+
end
|
56
|
+
|
57
|
+
def lock_task
|
58
|
+
date = DateTime.now
|
59
|
+
Caboose::Setting.create(:name => 'rets_update_running', :value => date.strftime('%F %T'))
|
60
|
+
return date
|
61
|
+
end
|
62
|
+
|
63
|
+
def unlock_task
|
64
|
+
Caboose::Setting.where(:name => 'rets_update_running').first.destroy
|
65
|
+
end
|
66
|
+
|
67
|
+
def unlock_task_if_last_updated(d)
|
68
|
+
setting = Caboose::Setting.where(:name => 'rets_update_running').first
|
69
|
+
unlock_task if setting && d.strftime('%F %T') == setting.value
|
70
|
+
end
|
71
|
+
|
72
|
+
#=============================================================================
|
18
73
|
def create_agents(c)
|
19
74
|
c.drop_table :rets_agents if c.table_exists?('rets_agents')
|
20
75
|
c.create_table :rets_agents do |t|
|