-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_apartment_notifier.rb
48 lines (40 loc) · 1.95 KB
/
new_apartment_notifier.rb
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
require 'bundler'
Bundler.setup
Encoding.default_external = Encoding::UTF_8
require 'pry'
require 'mongo_mapper'
require 'json/ext'
require 'httparty'
require 'oga'
require 'action_mailer'
require_relative 'mongo_setup'
require_relative 'action_mailer_setup'
require_relative 'apartment'
require_relative 'apartment_parser'
require_relative 'apartment_scrapper'
require_relative 'new_apartment_mailer'
require_relative 'new_apartment_saver'
MySettings = OpenStruct.new
MySettings.recipients = %w([email protected] [email protected])
TRESNJEVKA_SJEVER_URL = 'http://www.njuskalo.hr/?ctl=browse_ads&sort=new&categoryId=10920&locationId=2814&locationId_level_0=1153&locationId_level_1=1262&locationId_level_2=2814&priceLimitFrom=150&priceLimitTo=400&mainAreaFrom=34&mainAreaTo=65&adsWithImages=1&flatTypeId=0&floorCountId=0&roomCountId=0&flatFloorIdFrom=195&flatFloorIdTo=0&gardenAreaFrom=&gardenAreaTo=&balconyAreaFrom=&balconyAreaTo=&teraceAreaFrom=&teraceAreaTo=&yearBuiltFrom=&yearBuiltTo=&yearLastRebuildFrom=&yearLastRebuildTo='
CRNOMEREC_URL = 'http://www.njuskalo.hr/?ctl=browse_ads&sort=new&categoryId=10920&locationId=2597&locationId_level_0=1153&locationId_level_1=1248&locationId_level_2=2597&priceLimitFrom=159&priceLimitTo=400&mainAreaFrom=40&mainAreaTo=&adsWithImages=1&flatTypeId=0&floorCountId=0&roomCountId=0&flatFloorIdFrom=195&flatFloorIdTo=0&gardenAreaFrom=&gardenAreaTo=&balconyAreaFrom=&balconyAreaTo=&teraceAreaFrom=&teraceAreaTo=&yearBuiltFrom=&yearBuiltTo=&yearLastRebuildFrom=&yearLastRebuildTo='
areas = [
{
name: 'Tresnjevka sjever',
url: TRESNJEVKA_SJEVER_URL
},
{
name: 'Crnomerec',
url: CRNOMEREC_URL
}
]
areas.each do |area|
begin
NewApartmentSaver.new(url: area[:url], area: area[:name]).call
rescue => error
Logger.new('njuskalo-cron-errors.log').error(error)
end
end
# scrapper = ApartmentScrapper.new(TRESNJEVKA_SJEVER_URL)
# parser = ApartmentParser.new(scrapper.apartment_elements.first)
# binding.pry