SHARE
TWEET

Untitled

a guest Jan 20th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module TripPlanner
  2.  
  3.   class Gtfs
  4.     extend TripPlanner::Utils::Notifications
  5.     extend TripPlanner::Utils::Structure
  6.     attr_accessor :feed_zip_path, :osm_path, :planner
  7.  
  8.     def initialize(feed_zip_path,planner,osm_path)
  9.       self.feed_zip_path = feed_zip_path
  10.       self.planner = planner
  11.       self.osm_path = osm_path
  12.     end
  13.  
  14.     def import
  15.       # change trip_id in trips.txt and stop_times.txt because it should be like in Stopango.com
  16.       # TripPlanner::Parser.run(feed_zip_path,["trips.txt","stop_times.txt"])
  17.  
  18.       # create structure for current_planner gtfs file
  19.       self.class.create_structure([dir])
  20.  
  21.       # Remove all files from dir
  22.       self.class.clean_dir(dir)
  23.  
  24.       unless File.exist?("#{path}.gtfsdb")
  25.         # Create a GTFSDatabase (sqlite3 db) from a GTFS zip file
  26.         TripPlanner.run_command("gs_gtfsdb_compile #{feed_zip_path} #{path}.gtfsdb")
  27.         # Import a GTFS database to a graph file
  28.         TripPlanner.run_command("gs_import_gtfs #{osm_path}.gdb #{path}.gtfsdb")
  29.       end
  30.       self
  31.     end
  32.  
  33.     def path
  34.       File.join(dir,planner.name)
  35.     end
  36.  
  37.     # method create copy of every FeedZip passed in zips argument
  38.     # you should operate only on zip copy because you don't want brake any stopango module which use orginal zip files
  39.     def self.backup_zips(zips)
  40.       # remove all files from feed temp directory
  41.       clean_dir(TripPlanner.feeds_dir)
  42.  
  43.       zips.each do |zip|
  44.         result_file = File.join(TripPlanner.feeds_dir,zip.file_path)
  45.         send_notification("backup.zips.create", :dir => TripPlanner.feeds_dir, :filename => zip.file_path)
  46.         # create backup for every gtfs zip
  47.         FileUtils.cp zip.full_path, TripPlanner.feeds_dir
  48.         # return path to backuped gtfs zip      
  49.         yield result_file
  50.       end
  51.       send_notification("backup.zips.finish", :dir => TripPlanner.feeds_dir)
  52.       # remove all backuped gtfs zips from temp directory
  53.       clean_dir(TripPlanner.feeds_dir)          
  54.     end
  55.  
  56.   private
  57.  
  58.     def dir
  59.       File.join(TripPlanner.path,planner.name,"gtfs")
  60.     end
  61.  
  62.     def gtfs_files
  63.       Dir.glob File.join(dir,"#{planner.name}.*")
  64.     end
  65.  
  66.  
  67.   end
  68. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top