Skip to content

Commit 6ea4d81

Browse files
committed
create script to download transcripts in bulk
1 parent d7b562e commit 6ea4d81

5 files changed

Lines changed: 69 additions & 40 deletions

File tree

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ group :development do
5353
gem 'rack-mini-profiler'
5454
gem 'listen'
5555
gem 'timecop'
56+
gem 'wicked_pdf'
5657
end
5758

5859
group :test, :development do

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ GEM
507507
websocket-driver (0.7.6)
508508
websocket-extensions (>= 0.1.0)
509509
websocket-extensions (0.1.5)
510+
wicked_pdf (2.7.0)
511+
activesupport
510512
xpath (3.2.0)
511513
nokogiri (~> 1.8)
512514
zeitwerk (2.6.12)
@@ -589,6 +591,7 @@ DEPENDENCIES
589591
validate_url
590592
vcr
591593
webmock
594+
wicked_pdf
592595

593596
RUBY VERSION
594597
ruby 3.2.2p53

app/views/transcripts/_transcript.html.erb

Lines changed: 40 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1 @@
1-
<div class="row">
2-
<div class="col-md-8 col-md-offset-2">
3-
<h1 class="text-center">Transcript for Epicodus</h1>
4-
<p class="text-center"><em><strong>
5-
<%= @student.cohort.try(:description).try('include?', 'Data Engineering') ? 'Data Engineering' : 'Web and Mobile Development' %>
6-
</em></p>
7-
<p class="text-center">520 SW 6th Ave, Suite 300, Portland OR 97204</p>
8-
<p>Student: <strong><%= @student.name %></strong></p>
9-
<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>
10-
11-
<p>Courses: <strong>(does not include courses in progress)</strong></p>
12-
<ul>
13-
<% @completed_courses.each do |course| %>
14-
<li>
15-
<%= course.description %>
16-
<ul>
17-
<% course.code_reviews.where(journal: nil).or(course.code_reviews.where(journal: false)).each do |code_review| %>
18-
<li>
19-
<%= code_review.title %>
20-
<span class="pull-right"><em><%= code_review.status(@student) %></em></span>
21-
</li>
22-
<% end %>
23-
</ul>
24-
</li>
25-
<% end %>
26-
</ul>
27-
28-
<% if @completed_courses.non_internship_courses.any? %>
29-
<% if @student.total_attendance_score >= 90.0 %>
30-
<p>Epicodus requires students to attend class at least 90% of the time. This student met that requirement.</p>
31-
<% end %>
32-
<% end %>
33-
34-
<p><%= image_tag "signature.png" %></p>
35-
<p><strong>Michael Kaiser-Nyman, President</strong></p>
36-
<p>Date: <%= @completed_courses.last.end_date.strftime('%B %d, %Y') %></p>
37-
<br>
38-
<p>Epicodus maintains student transcripts for 50 years.</p>
39-
</div>
40-
</div>
1+
<%= render partial: 'transcript', locals: {student: @student, completed_courses: @completed_courses} %>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# USAGE: before running, brew install wkhtmltopdf
2+
require 'wicked_pdf'
3+
4+
task :save_all_transcripts => [:environment] do
5+
students = Student.select {|s| s.courses.any?}
6+
puts "Total students: #{students.count}"
7+
students.each do |student|
8+
puts student.email
9+
@student = student
10+
@completed_courses = student.courses.order(:start_date)
11+
12+
html = ActionController::Base.new.render_to_string(
13+
template: 'transcripts/_transcript',
14+
locals: { student: @student, completed_courses: @completed_courses }
15+
)
16+
17+
pdf = WickedPdf.new.pdf_from_string(html)
18+
19+
file_path = Rails.root.join('transcripts-output', "#{student.name.parameterize}_#{student.email}.pdf")
20+
File.open(file_path, 'wb') do |file|
21+
file << pdf
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)