Skip to content

Commit

Permalink
create script to download transcripts in bulk
Browse files Browse the repository at this point in the history
  • Loading branch information
ashgoren committed Jan 12, 2024
1 parent d7b562e commit 6ea4d81
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 40 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ group :development do
gem 'rack-mini-profiler'
gem 'listen'
gem 'timecop'
gem 'wicked_pdf'
end

group :test, :development do
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ GEM
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
wicked_pdf (2.7.0)
activesupport
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.12)
Expand Down Expand Up @@ -589,6 +591,7 @@ DEPENDENCIES
validate_url
vcr
webmock
wicked_pdf

RUBY VERSION
ruby 3.2.2p53
Expand Down
40 changes: 40 additions & 0 deletions app/views/transcripts/_transcript.html.erb

Large diffs are not rendered by default.

41 changes: 1 addition & 40 deletions app/views/transcripts/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,40 +1 @@
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h1 class="text-center">Transcript for Epicodus</h1>
<p class="text-center"><em><strong>
<%= @student.cohort.try(:description).try('include?', 'Data Engineering') ? 'Data Engineering' : 'Web and Mobile Development' %>
</em></p>
<p class="text-center">520 SW 6th Ave, Suite 300, Portland OR 97204</p>
<p>Student: <strong><%= @student.name %></strong></p>
<p>Dates Enrolled: <%= @student.courses.order(:start_date).first.start_date.strftime('%B %d, %Y') %> - <%= @student.courses.order(:start_date).last.end_date.strftime('%B %d, %Y') %></p>

<p>Courses: <strong>(does not include courses in progress)</strong></p>
<ul>
<% @completed_courses.each do |course| %>
<li>
<%= course.description %>
<ul>
<% course.code_reviews.where(journal: nil).or(course.code_reviews.where(journal: false)).each do |code_review| %>
<li>
<%= code_review.title %>
<span class="pull-right"><em><%= code_review.status(@student) %></em></span>
</li>
<% end %>
</ul>
</li>
<% end %>
</ul>

<% if @completed_courses.non_internship_courses.any? %>
<% if @student.total_attendance_score >= 90.0 %>
<p>Epicodus requires students to attend class at least 90% of the time. This student met that requirement.</p>
<% end %>
<% end %>

<p><%= image_tag "signature.png" %></p>
<p><strong>Michael Kaiser-Nyman, President</strong></p>
<p>Date: <%= @completed_courses.last.end_date.strftime('%B %d, %Y') %></p>
<br>
<p>Epicodus maintains student transcripts for 50 years.</p>
</div>
</div>
<%= render partial: 'transcript', locals: {student: @student, completed_courses: @completed_courses} %>
24 changes: 24 additions & 0 deletions lib/tasks/save_all_transcripts.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# USAGE: before running, brew install wkhtmltopdf
require 'wicked_pdf'

task :save_all_transcripts => [:environment] do
students = Student.select {|s| s.courses.any?}
puts "Total students: #{students.count}"
students.each do |student|
puts student.email
@student = student
@completed_courses = student.courses.order(:start_date)

html = ActionController::Base.new.render_to_string(
template: 'transcripts/_transcript',
locals: { student: @student, completed_courses: @completed_courses }
)

pdf = WickedPdf.new.pdf_from_string(html)

file_path = Rails.root.join('transcripts-output', "#{student.name.parameterize}_#{student.email}.pdf")
File.open(file_path, 'wb') do |file|
file << pdf
end
end
end

0 comments on commit 6ea4d81

Please sign in to comment.