Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Shopping
ICON_URL = "http://www.google.com/s2/favicons?domain="
# Metro Deal
METRODEAL_URL = "http://www.metrodeal.com/"
METRODEAL_SURL = "#{METRODEAL_URL}catalog/?q="
def self.metrodeal(page)
items = Array.new
page.css("body div.deals-content .deals-item-container").each do |data|
items << metrodeal_info(data)
end
return items
end
def self.metrodeal_info(data)
if link = data.css(".deals-item-title a").first()
resp = Hash.new
resp[:icon] = "#{ICON_URL}#{CGI.escape(METRODEAL_URL)}"
resp[:type] = 'MetroDeal'
resp[:title] = clean_title(link.children)
resp[:url] = link['href']
resp[:discount] = data.css(".price-details").first().text.gsub("OFF", "").strip
resp[:price] = clean_price(data.css(".price-tag").first().text)
resp[:buyers] = data.css(".price-details").last().text.gsub("bought", "").strip
return resp
end
end
OLX_URL = "http://www.olx.ph/"
OLX_SURL = "#{OLX_URL}index.php/classifieds+directory/q/"
def self.olx(page)
items = Array.new
page.css("body #listings .listingItem").each do |data|
items << olx_info(data)
end
return items
end
def self.olx_info(data)
if link = data.css("a.listingLink").first()
resp = Hash.new
resp[:icon] = "#{ICON_URL}#{CGI.escape(OLX_URL)}"
resp[:type] = 'OLX_URL'
resp[:title] = clean_title(data.css(".listingInfo .listingTitle").text)
resp[:url] = link['href']
resp[:price] = clean_price(data.css(".listingInfo .listingPrice").first().text)
return resp
end
end
AYOSDITO_URL = "http://www.ayosdito.ph/"
AYOSDITO_SURL = "#{AYOSDITO_URL}li?q="
def self.ayosdito(page)
items = Array.new
page.css("body .listing_with_star_ads .list_ads").each do |data|
items << ayosdito_info(data)
end
return items
end
def self.ayosdito_info(data)
if link = data.css(".listing_ads_title a").first()
resp = Hash.new
resp[:icon] = "#{ICON_URL}#{CGI.escape(AYOSDITO_URL)}"
resp[:type] = 'AyosDito'
resp[:title] = clean_title(link.css("strong").text)
resp[:url] = link['href']
resp[:price] = clean_price(ayosdito_custom_price(data))
return resp
end
end
private
def self.clean_price(price)
price.gsub(/[^0-9.]/i, '').to_i
end
def self.clean_title(title)
ActionView::Base.full_sanitizer.sanitize(title.to_s).gsub("\n","").strip
end
def self.ayosdito_custom_price(data)
index1 = data.to_s.rindex("price_suffix\">") + 23
data.to_s[index1..data.to_s.index("<br>",index1)-1]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.