Module: Markify

Defined in:
lib/markify/version.rb,
lib/markify.rb

Overview

Copyright Daniel Meißner <[email protected]>, 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/>.

Defined Under Namespace

Modules: OptParser, Scraper, Settings Classes: Bot, Database, Mark

Constant Summary collapse

VERSION =
'0.2.2'
NAME =
'markify'
DESCRIPTION =
"\#{Markify::NAME.capitalize} is a ruby script to detect new marks or course assessments in the student\ninformation system of your university. If \#{Markify::NAME} detects new marks, they will send you a XMPP message for\nevery change. Supported universities: University of Applied Sciences Bonn-Rhein-Sieg.\n"
LICENCE =
"\#{Markify::NAME.capitalize} - v\#{Markify::VERSION}\nReleased under the GNU GENERAL PUBLIC LICENSE Version 3. \u00A9 Daniel Mei\u00DFner, 2013\n"
SUMMARY =
"Mark notify script for different universities.\n"

Class Method Summary collapse

Class Method Details

.run!Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 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