Skip to content

Commit

Permalink
change api class name and little refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
petersonfs committed Oct 25, 2012
1 parent c5b5ccd commit bdc102d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
require "open-uri"
require "jbuilder"

class BusaoCwb < Sinatra::Base
class BusNow < Sinatra::Base
BASE_URL = "http://www.urbs.curitiba.pr.gov.br/horario-de-onibus/"

get "/api/schedules/:code.json" do |code|
content_type :json

items = []

page = Nokogiri::HTML.parse(open(BASE_URL + "#{code}"), BASE_URL, "UTF-8")
page = crawl_page "#{code}"
name = page.css("h2.left.schedule")[0].content
page.css("div.bg-white.round-bl-60.width96.margin-medium-top.clearfix").each do |line|
station = line.css("h3.schedule")[0].content
Expand All @@ -36,7 +36,8 @@ class BusaoCwb < Sinatra::Base

items = []

page = Nokogiri::HTML.parse(open(BASE_URL + "#{code}/#{type}"), BASE_URL, "UTF-8")
crawl_page "#{code}/#{type}"

name = page.css("h2.left.schedule")[0].content
page.css("div.bg-white.round-bl-60.width96.margin-medium-top.clearfix").each do |line|
station = line.css("h3.schedule")[0].content
Expand All @@ -54,4 +55,9 @@ class BusaoCwb < Sinatra::Base
end
end
end

private
def crawl_page(url)
Nokogiri::HTML.parse(open(BASE_URL + url), BASE_URL, "UTF-8")
end
end
2 changes: 1 addition & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require "./api"

run BusaoCwb
run BusNow

0 comments on commit bdc102d

Please sign in to comment.