mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
Load survey responses from sftp folder
This commit is contained in:
parent
1426e7cc63
commit
03c6bff7bb
38 changed files with 128 additions and 147272 deletions
28
app/services/sftp/directory.rb
Normal file
28
app/services/sftp/directory.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
require 'net/sftp'
|
||||
require 'uri'
|
||||
require 'csv'
|
||||
|
||||
module Sftp
|
||||
class Directory
|
||||
def self.open(path: '/data/survey_responses/', &block)
|
||||
sftptogo_url = ENV['SFTPTOGO_URL']
|
||||
puts sftptogo_url
|
||||
uri = URI.parse(sftptogo_url)
|
||||
Net::SFTP.start(uri.host, uri.user, password: uri.password) do |sftp|
|
||||
sftp.dir.foreach(path) do |entry|
|
||||
filename = entry.name
|
||||
puts filename
|
||||
|
||||
sftp.file.open(filepath(path:, filename:), 'r', &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.filepath(path:, filename:)
|
||||
path += '/' unless path.end_with?('/')
|
||||
"#{path}#{filename}"
|
||||
end
|
||||
|
||||
private_class_method :filepath
|
||||
end
|
||||
end
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
require 'net/sftp'
|
||||
require 'uri'
|
||||
require 'csv'
|
||||
|
||||
module Sftp
|
||||
class Downloader
|
||||
def initialize
|
||||
sftptogo_url = ENV['SFTPTOGO_URL']
|
||||
uri = URI.parse(sftptogo_url)
|
||||
Net::SFTP.start(uri.host, uri.user, password: uri.password) do |sftp|
|
||||
# download a file or directory from the remote host
|
||||
# open and read from a pseudo-IO for a remote file
|
||||
# sftp.file.open('/mciea/data/canary.csv', 'r') do |f|
|
||||
# CSV.parse(f.read) do |row|
|
||||
# puts row
|
||||
# end
|
||||
# end
|
||||
|
||||
# list the entries in a directory
|
||||
sftp.dir.foreach('/mciea/data/') do |entry|
|
||||
puts entry.longname
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
33
app/services/sftp/race_loader.rb
Normal file
33
app/services/sftp/race_loader.rb
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
require 'net/sftp'
|
||||
require 'uri'
|
||||
require 'csv'
|
||||
|
||||
module Sftp
|
||||
class RaceLoader
|
||||
def self.load_data(path: '/data/survey_responses/')
|
||||
SurveyItemResponse.update_all(student_id: nil)
|
||||
StudentRace.delete_all
|
||||
Student.delete_all
|
||||
|
||||
sftptogo_url = ENV['SFTPTOGO_URL']
|
||||
uri = URI.parse(sftptogo_url)
|
||||
Net::SFTP.start(uri.host, uri.user, password: uri.password) do |sftp|
|
||||
sftp.dir.foreach(path) do |entry|
|
||||
filename = entry.name
|
||||
puts filename
|
||||
|
||||
sftp.file.open(filepath(path:, filename:), 'r') do |f|
|
||||
StudentLoader.from_file(file: f, rules: [Rule::SkipNonLowellSchools])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.filepath(path:, filename:)
|
||||
path += '/' unless path.end_with?('/')
|
||||
"#{path}#{filename}"
|
||||
end
|
||||
|
||||
private_class_method :filepath
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue