-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
78 lines (63 loc) · 1.87 KB
/
app.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
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
require("bundler/setup")
require 'open-uri'
require 'date'
Bundler.require(:default)
Dir[File.dirname(__FILE__) + '/lib/*.rb'].each { |file| require file }
Dynopoker.configure do |config|
config.address = 'https://macbook-tracker.herokuapp.com/update'
config.poke_frequency = 3600 # default is 1800s (30min)
end
get '/' do
@type = "Normal"
@search_macs = Mac.where("normal = true")
@macs = Mac.all
erb(:index)
end
post ('/search') do
if params['type'] != "all"
params['type'] == "true" ? @type = "Normal" : @type = "Damaged/Unusual"
search_type = "normal = #{params['type']}"
else
@type = "All"
end
if params['min_price'] != ''
search_min_price = "price >= #{params['min_price']}"
end
if params['max_price'] != ''
search_max_price = "price <= #{params['max_price']}"
end
if search_type
combined_search = search_type
end
if search_min_price && combined_search
combined_search += " and " + search_min_price
elsif search_min_price
combined_search = search_min_price
end
if search_max_price && combined_search
combined_search += " and " + search_max_price
elsif search_max_price
combined_search = search_max_price
end
if !combined_search
combined_search = ''
end
@search_macs = Mac.where(combined_search).order(params['sort'])
@macs = Mac.all
erb(:index)
end
get '/update' do
# default link and city
search_link = 'https://portland.craigslist.org/search/sss?excats=5-15-22-2-24-1-4-19-1-1-1-2-1-3-6-10-1-1-1-2-2-8-1-1-1-1-1-4-1-3-1-3-1-1-1-1-7-1-1-1-1-1-3-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-3-1-1-1-1-1&query=macbook&sort=rel'
city = "Portland"
# if user inputs link chang default link
# if params['link'] != ''
# search_link = params['link']
# end
Mac.scrape_craigslsit(search_link, city)
redirect '/remove'
end
get '/remove' do
Mac.remove_old
redirect '/'
end