lib/gtfs/realtime.rb in gtfs-realtime-0.2.1 vs lib/gtfs/realtime.rb in gtfs-realtime-0.2.2

- old
+ new

@@ -5,10 +5,11 @@ # we must load our Sequel DB schema first require "gtfs/realtime/database" require "gtfs/gtfs_gem_patch" +require "gtfs/realtime/calendar_date" require "gtfs/realtime/configuration" require "gtfs/realtime/route" require "gtfs/realtime/service_alert" require "gtfs/realtime/shape" require "gtfs/realtime/stop" @@ -41,10 +42,21 @@ static_data = GTFS::Source.build(@configuration.static_feed) return unless static_data GTFS::Realtime::Model.db.transaction do + GTFS::Realtime::CalendarDate.dataset.delete + GTFS::Realtime::CalendarDate.multi_insert( + static_data.calendar_dates.collect do |calendar_date| + { + service_id: calendar_date.service_id.strip, + date: Date.strptime(calendar_date.date, "%Y%m%d"), + exception_type: calendar_date.exception_type + } + end + ) + GTFS::Realtime::Route.dataset.delete GTFS::Realtime::Route.multi_insert( static_data.routes.collect do |route| { id: route.id.strip, @@ -98,11 +110,12 @@ { id: trip.id.strip, headsign: trip.headsign.strip, route_id: trip.route_id.strip, service_id: trip.service_id.strip, - shape_id: trip.shape_id.strip + shape_id: trip.shape_id.strip, + direction_id: trip.direction_id } end ) end end @@ -172,10 +185,14 @@ private def get_entities(path) return [] if path.nil? - data = Net::HTTP.get(URI.parse(path)) + if File.exists?(path) + data = File.open(path, 'r'){|f| f.read} + else + data = Net::HTTP.get(URI.parse(path)) + end feed = Transit_realtime::FeedMessage.decode(data) feed.entity # array of entities end end end