123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- class ResgenController
- def initialize
- @model = ResgenModel.new
- @view = ResgenView.new
- @time = Time.new
- @config = @model.config
- end
- def run
- if @config['driver'] == nil
- # first run, so get all the config values we'll need set
- @model.firstrun
- @view.welcome
- # user has been notified to restart
- exit
- end
- # make sure everything is pathed appropriately
- @model.test
- require 'odf-report'
- require 'combine_pdf'
-
- # if arguments are passed, the user might be requesting reports
- if !ARGV.empty? && ARGV[0] == 'week' || ARGV[0] == 'month' || ARGV[0] == 'year'
- report = ResgenReports.new
- report.report ARGV[0]
- exit
- elsif !ARGV.empty?
- @view.arg_error
- exit
- end
- # close out any libreoffice processes
- @model.runproc('soffice')
- # prompt the user with definitions from the view
- @view.prompt_position
- position = gets.chomp
- @view.prompt_company
- company = gets.chomp
- # initialize the company directory name
- scrape_dir = @model.sanitize company
- scrape_fn = @model.sanitize position
- employer_dir = @config['appliedir'] + scrape_dir + '/'
- # make sure this is a new application
- @model.checkdir employer_dir
- @view.prompt_url
- url = gets.chomp
- # send the scraper to grab a copy of the posting
- @view.job_scrape(url)
- @model.scrape(url, employer_dir + scrape_fn + @time.strftime("-%-m-%-d-%y") +'.html')
- resgen = ODFReport::Report.new(@config['coverpath']) do |merge|
- # pass it to the writer doc - if you want to further customize your cover sheet: https://notabug.org/angela/resgen/wiki/Custom-Fields
- merge.add_field :date, @time.strftime("%A, %B %-d, %Y")
- merge.add_field :position, "#{position}"
- merge.add_field :company, "#{company}"
- # append new data to the existing spreadsheet
- CSV.open(@config['appliedir'] + 'applied.csv', 'ab') do |csv|
- csv << [Time.now,"#{company}", "#{position}","#{url}","",""]
- end
- end
- # complete the libre office file creation
- resgen.generate('output.odt')
- # convert odt to pdf file
- @model.makepdf('output.odt')
- # remove the odt file, now that we're done with it
- @model.del('output.odt')
- # create a pdf of the resume to merge
- @model.makepdf(@config['resumepath'])
- # merge time
- respath = File.basename(@config['resumepath'], File.extname(@config['resumepath']))
- @model.mergepdf('output.pdf', respath + ".pdf", @config['destination'], @config['outputfilename'], employer_dir)
- # display success notice
- @view.completion
- # cleanup
- @model.del('output.pdf')
- @model.del(respath + ".pdf")
- end
- # catch a user keying cntrl + c to gracefully close
- Signal.trap("INT") {
- puts "\nExit request received. Closing Resgen; have a nice day!"
- exit
- }
- end
|