Skip to content

Commit 22e5fdf

Browse files
committed
create script to download transcripts in bulk
1 parent addb4b6 commit 22e5fdf

5 files changed

Lines changed: 66 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
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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">400 SW 6th Ave, Suite 800, 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.days_since_start_of_program.any? && 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>
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">400 SW 6th Ave, Suite 800, 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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require 'wicked_pdf'
2+
3+
task :save_all_transcripts => [:environment] do
4+
students = Student.select {|s| s.courses.any?}
5+
students.each do |student|
6+
@student = student
7+
@completed_courses = student.courses.order(:start_date)
8+
9+
html = ActionController::Base.new.render_to_string(
10+
template: 'transcripts/_transcript',
11+
locals: { student: @student, completed_courses: @completed_courses }
12+
)
13+
14+
pdf = WickedPdf.new.pdf_from_string(html)
15+
16+
file_path = Rails.root.join('transcripts-output', "#{student.name.parameterize}_#{student.email}.pdf")
17+
File.open(file_path, 'wb') do |file|
18+
file << pdf
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)