module Markify

Copyright Daniel Meißner <meise+markify@3st.be>, 2013

This file is part of Markify.

Markify is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Markify is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Markify. If not, see <www.gnu.org/licenses/>.

Constants

DESCRIPTION
LICENCE
NAME
SUMMARY
VERSION

Public Class Methods

run!() click to toggle source
# File lib/markify.rb, line 37
def self.run!
  @options      = Markify::OptParser.parse!
  @config       = Markify::Settings.load!(@options[:config_file])
  @scraper      = nil

  mark_database = Markify::Database.new(@config['general']['database_file'])

  case @config['university']['acronym'].downcase
    when /hbrs/
      @scraper = Markify::Scraper::Hbrs.new(@config['university']['login_name'],
                                            @config['university']['login_password'])
    else
      puts 'No support for your university.'
      exit
  end

  if @options[:test]
    Markify::Settings.test_settings(@config, @scraper)
    exit
  end

  all_marks = @scraper.scrape!
  new_marks = mark_database.check_for_new_marks(all_marks)

  if new_marks.count == 0 && (@config['general']['verbose'] || @options[:noop])
    puts "No new marks."
    exit 0
  end

  bot = Markify::Bot.new(@config['xmpp']['bot_id'], @config['xmpp']['bot_password']) if @options[:send] &&
                                                                                        new_marks.count > 0

  new_marks.sort_by{|mark| mark.date}.each do |mark|
    unless @options[:noop]
      mark_database.write_checksum(mark.hash)
    end

    bot.send_message(@config['xmpp']['recipients'], mark.to_s) if @options[:send]

    puts mark.to_s if @config['general']['verbose'] || @options[:verbose]
  end
end