Commit e26728c2 authored by Zac Wood's avatar Zac Wood

Fixed seeds and Gemfile merge conflicts

parent 31de7866
......@@ -185,18 +185,13 @@ PLATFORMS
DEPENDENCIES
byebug
capybara (~> 2.13)
<<<<<<< HEAD:schedules_api/Gemfile.lock
httparty
icalendar
jbuilder (~> 2.5)
listen (>= 3.0.5, < 3.2)
nokogiri
pry
pry-doc
=======
httparty
jbuilder (~> 2.5)
listen (>= 3.0.5, < 3.2)
nokogiri
>>>>>>> parser:schedules_api/Gemfile.lock
puma (~> 3.7)
rails (~> 5.1.6)
rubyXL
......
......@@ -5,25 +5,78 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
require 'rubyXL'
require_relative 'excel_loader'
Semester.delete_all
Course.delete_all
Section.delete_all
require_relative 'patriot_web_parser'
require 'thwait'
require 'httparty'
require 'nokogiri'
require 'json'
threads = []
total = []
parser = PatriotWeb::Parser.new
semester = parser.parse_semesters.first
parser.parse_subjects(semester).each do |subject|
threads << Thread.new {
total << parser.parse_courses_in_subject(subject)
}
end
# For testing, only get first subject
# subject = parser.parse_subjects(semester).first
# total << parser.parse_courses_in_subject(subject)
ThreadsWait.all_waits(*threads)
Closure.delete_all
Section.delete_all
Course.delete_all
Semester.delete_all
semester = Semester.create! season: 'Fall', year: 2018
semester.save!
total.each do |subject|
subject.each_value do |section|
next unless (section.key? "date_range") && (section.key? "instructors") && (section.key? "days")
course = Course.find_or_create_by(subject: section[:subj],
course_number: section[:code])
loader = if Rails.env.test?
ExcelLoader.new 'db/data/testdata.xlsx'
else
ExcelLoader.new 'db/data/allsections.xlsx'
end
course.semester = semester
course.save!
semester = Semester.where(season: "Fall", year: "2018").first
section_name = "#{section[:subj]} #{section[:code]} #{section[:sect]}"
puts "Adding #{section_name}..."
start_time = if section.key? "time"
section["time"].split(' - ').first
else
"N/A"
end
end_time = if section.key? "time"
section["time"].split(' - ').last
else
"N/A"
end
Section.create!(name: section_name,
crn: section[:crn],
title: section[:name],
location: section["where"],
days: section["days"],
start_date: section["date_range"].split(' - ').first,
end_date: section["date_range"].split(' - ').last,
start_time: start_time,
end_time: end_time,
instructor: section["instructors"].split(' ').map { |word| word unless word.empty? }.join(' '),
course: course)
end
end
Closure.create! date: Date.new(2018, 9, 3), semester: semester
Closure.create! date: Date.new(2018, 10, 8), semester: semester
(21..25).each { |n| Closure.create! date: Date.new(2018, 11, n), semester: semester }
(10..19).each { |n| Closure.create! date: Date.new(2018, 12, n), semester: semester }
loader.load_data
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment