Created
October 8, 2015 16:58
-
-
Save jonahgeorge/73d6ecdb1f9dd4283023 to your computer and use it in GitHub Desktop.
MECOP Merge Resume PDFs using Ghostscript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'open-uri' | |
| require 'csv' | |
| class Student | |
| attr_accessor :id | |
| attr_accessor :stage | |
| def initialize(id:, stage:) | |
| self.id = id | |
| self.stage = stage | |
| end | |
| # Fetches the student's resume using the mecopinc.org preview-resume-form. | |
| # preview-resume-form requires an authenticated cookie. | |
| def fetch_resume(cookie) | |
| url = "https://www.mecopinc.org/members/preview-resume-form?type=#{self.stage}&id=#{self.id}" | |
| puts url | |
| File.open("./#{self.id}.pdf", "w") do |f| | |
| pdf = open(url, "Cookie" => cookie) | |
| pdf.each_line do |line| | |
| f.write(line) | |
| end | |
| end | |
| end | |
| end | |
| students = [] | |
| CSV.foreach(ARGV[0]) do |row| | |
| students << Student.new(id: row[0], stage: row[1]) | |
| end | |
| # Iterate over teams and fetch each student's resume. | |
| students.each do |student| | |
| puts "#{student.id}" | |
| student.fetch_resume(ARGV[1]) | |
| end | |
| # Sort students by last name, first name and construct valid filenames | |
| files = students.map{|s| "./#{s.id}.pdf" }.join(' ') | |
| # Set CLI options for GhostScript | |
| # -q Quiet | |
| # -dNOPAUSE Disables the prompt and pause at the end of each page. | |
| # -dBATCH Causes Ghostscript to exit after processing all files named on the | |
| # command line, rather than going into an interactive loop reading PostScript | |
| # commands. Equivalent to putting -c quit at the end of the command line. | |
| # -sDEVICE Selects an alternate initial output device, in this case pdfwrite. | |
| options = "-q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite" | |
| # Append resumes together using GhostScript | |
| system "gs #{options} -sOutputFile=2015_cecop_resumes.pdf #{files}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment