-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api para consultar os horarios de onibus por linha
- Loading branch information
0 parents
commit 178432d
Showing
7 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: bundle exec thin start -p $PORT |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require "./api" | ||
|
||
run BusaoCwb |