Skip to content

Instantly share code, notes, and snippets.

@donpdonp
Created December 7, 2011 19:10
Show Gist options
  • Save donpdonp/1444169 to your computer and use it in GitHub Desktop.
Save donpdonp/1444169 to your computer and use it in GitHub Desktop.
trimet gtfs in ruby
## stream-read.rb
require 'gtfs-realtime.pb'
require 'eventmachine'
require 'em-http-request'
trimet = YAML.load(File.open('trimet.yaml'))
EventMachine.run do
http = EventMachine::HttpRequest.new('http://developer.trimet.org/ws/V1/FeedSpecAlerts/').get(:query => trimet)
http.callback do
p http.response_header
msg = TransitRealtime::FeedMessage.new.parse_from_string(http.response)
msg.entity.each do |e|
if e.trip_update
p "TRIP_UPDATE "+e.trip_update
end
if e.vehicle
p "VEHICLE "+e.vehicle
end
if e.alert
p "ALERT "
p e.alert.description_text.translation
end
end
end
end
## trimet.yaml
---
appID: 9999999999999999999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment