Skip to content

Commit

Permalink
api para consultar os horarios de onibus por linha
Browse files Browse the repository at this point in the history
  • Loading branch information
petersonfs committed Oct 22, 2012
0 parents commit 178432d
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source :rubygems

gem "sinatra"
gem "thin"
gem "nokogiri"
gem "jbuilder"
gem "foreman"
38 changes: 38 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
GEM
remote: http://rubygems.org/
specs:
activesupport (3.2.8)
i18n (~> 0.6)
multi_json (~> 1.0)
daemons (1.1.9)
eventmachine (1.0.0)
foreman (0.60.2)
thor (>= 0.13.6)
i18n (0.6.1)
jbuilder (0.8.2)
activesupport (>= 3.0.0)
multi_json (1.3.6)
nokogiri (1.5.5)
rack (1.4.1)
rack-protection (1.2.0)
rack
sinatra (1.3.3)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
thin (1.5.0)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
thor (0.16.0)
tilt (1.3.3)

PLATFORMS
ruby

DEPENDENCIES
foreman
jbuilder
nokogiri
sinatra
thin
Empty file added LICENSE.md
Empty file.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: bundle exec thin start -p $PORT
Empty file added README.md
Empty file.
32 changes: 32 additions & 0 deletions api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# encoding: utf-8
require "sinatra/base"
require "nokogiri"
require "open-uri"
require "jbuilder"

class BusaoCwb < 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")
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
type = line.css("p.grey.margin0")[0].content.match("([^-]+$)")[0].strip
schedules = line.css("li.bold").map { |s| s.content }
items << { :station => station, :type => type, :schedules => schedules }
end

Jbuilder.encode do |json|
json.name name
json.items items do |item|
json.station item[:station]
json.type item[:type]
json.schedules item[:schedules]
end
end
end
end
3 changes: 3 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require "./api"

run BusaoCwb

0 comments on commit 178432d

Please sign in to comment.