controller.rb 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. class ResgenController
  2. def initialize
  3. @model = ResgenModel.new
  4. @view = ResgenView.new
  5. @time = Time.new
  6. @config = @model.config
  7. end
  8. def run
  9. if @config['driver'] == nil
  10. # first run, so get all the config values we'll need set
  11. @model.firstrun
  12. @view.welcome
  13. # user has been notified to restart
  14. exit
  15. end
  16. # make sure everything is pathed appropriately
  17. @model.test
  18. require 'odf-report'
  19. require 'combine_pdf'
  20. # if arguments are passed, the user might be requesting reports
  21. if !ARGV.empty? && ARGV[0] == 'week' || ARGV[0] == 'month' || ARGV[0] == 'year'
  22. report = ResgenReports.new
  23. report.report ARGV[0]
  24. exit
  25. elsif !ARGV.empty?
  26. @view.arg_error
  27. exit
  28. end
  29. # close out any libreoffice processes
  30. @model.runproc('soffice')
  31. # prompt the user with definitions from the view
  32. @view.prompt_position
  33. position = gets.chomp
  34. @view.prompt_company
  35. company = gets.chomp
  36. # initialize the company directory name
  37. scrape_dir = @model.sanitize company
  38. scrape_fn = @model.sanitize position
  39. employer_dir = @config['appliedir'] + scrape_dir + '/'
  40. # make sure this is a new application
  41. @model.checkdir employer_dir
  42. @view.prompt_url
  43. url = gets.chomp
  44. # send the scraper to grab a copy of the posting
  45. @view.job_scrape(url)
  46. @model.scrape(url, employer_dir + scrape_fn + @time.strftime("-%-m-%-d-%y") +'.html')
  47. resgen = ODFReport::Report.new(@config['coverpath']) do |merge|
  48. # pass it to the writer doc - if you want to further customize your cover sheet: https://notabug.org/angela/resgen/wiki/Custom-Fields
  49. merge.add_field :date, @time.strftime("%A, %B %-d, %Y")
  50. merge.add_field :position, "#{position}"
  51. merge.add_field :company, "#{company}"
  52. # append new data to the existing spreadsheet
  53. CSV.open(@config['appliedir'] + 'applied.csv', 'ab') do |csv|
  54. csv << [Time.now,"#{company}", "#{position}","#{url}","",""]
  55. end
  56. end
  57. # complete the libre office file creation
  58. resgen.generate('output.odt')
  59. # convert odt to pdf file
  60. @model.makepdf('output.odt')
  61. # remove the odt file, now that we're done with it
  62. @model.del('output.odt')
  63. # create a pdf of the resume to merge
  64. @model.makepdf(@config['resumepath'])
  65. # merge time
  66. respath = File.basename(@config['resumepath'], File.extname(@config['resumepath']))
  67. @model.mergepdf('output.pdf', respath + ".pdf", @config['destination'], @config['outputfilename'], employer_dir)
  68. # display success notice
  69. @view.completion
  70. # cleanup
  71. @model.del('output.pdf')
  72. @model.del(respath + ".pdf")
  73. end
  74. # catch a user keying cntrl + c to gracefully close
  75. Signal.trap("INT") {
  76. puts "\nExit request received. Closing Resgen; have a nice day!"
  77. exit
  78. }
  79. end