Class: GamesAndRpgParadise::Lpc::Geas::Forum

Inherits:
Base
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/lpc/geas/forum.rb

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
SHOW_WHEN_TO_RETRY_NEXT =
#

SHOW_WHEN_TO_RETRY_NEXT

#
false
OUTPUT_NAMESPACE =
#

OUTPUT_NAMESPACE

#
false
REMOTE_URL =
#

REMOTE_URL

#
'http://s95103930.onlinehome.us/geas/forum/'
NO_USERS_MSG =
#

NO_USERS_MSG

#
'No registered users'
SEARCH_STRING =
#

SEARCH_STRING

#
'<br />Registered users: '
INITIAL_DELAY =
#

INITIAL_DELAY

#
60 * 3
USE_RANDOMIZED_DELAY =
#

USE_RANDOMIZED_DELAY

#
true
REGEX =
#

REGEX

#
Regexp.quote(SEARCH_STRING)+'(.+)'
SHALL_WE_REPORT_WHEN_NOBODY_IS_CURRENTLY_LOGGED_IN =
#

SHALL_WE_REPORT_WHEN_NOBODY_IS_CURRENTLY_LOGGED_IN

#
false
FORUM_IS_UNAVAILABLE =
#

FORUM_IS_UNAVAILABLE

The forum may be unavailable.

#
'Forum temporarily closed for upgrades.'

Constants included from Base::Extensions::Colours

Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS

Constants included from CommonExtensions

CommonExtensions::CONTROL_C_CODE, CommonExtensions::N

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base::Extensions::Colours

ecomment, #efancy, #eparse, #forestgreen, #gold, #grey, #lightblue, #mediumseagreen, #mediumslateblue, #peru, sdir, sfancy, #sfile, simp, #teal, #yellow

Methods included from Base::Extensions::CommandlineArguments

#commandline_arguments?, #filter_away_commandline_arguments, #first_argument?, #first_non_hyphened_argument?, #set_commandline_arguments

Methods included from CommonExtensions

#cat, #cd, #cliner, #copy_file, #delete, #dirname_but_retains_the_trailing_slash, #disable_colours, #ensure_that_the_log_directory_exists, #esystem, #get_user_input, #infer_the_namespace, #is_on_roebe?, #log_dir?, #mkdir, #mkdir_then_cd_into_it, #mv, #namespace?, #opne, #project_base_directory?, #project_image_directory?, #project_yaml_directory?, #rds, #remove_this_directory, #rename_file, #reset_the_internal_hash, #return_pwd, #return_today, #touch_file, #wrap, #write_what_into

Constructor Details

#initialize(i = nil, run_already = true) ⇒ Forum

#

initialize

#


135
136
137
138
139
140
141
142
143
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 135

def initialize(
    i           = nil,
    run_already = true
  )
  register_sigint
  reset
  set_commandline(i)
  run if run_already
end

Class Method Details

.increase_delay?Boolean

#

GamesAndRpgParadise::Geas.increase_delay?

#

Returns:

  • (Boolean)


529
530
531
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 529

def self.increase_delay?
  false
end

.opnnObject

#

opnn

#


881
882
883
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 881

def self.opnn
  Opn.opn(namespace: NAMESPACE) if OUTPUT_NAMESPACE
end

.run_in_loop(for_n_seconds = 35_000) ⇒ Object

#

GamesAndRpgParadise::Geas::Forum.run_in_loop

Use this to run in a loop.

#


751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 751

def self.run_in_loop(for_n_seconds = 35_000)
  @iteration_step = INITIAL_DELAY
  loop {
    counter = 0
    case for_n_seconds
    when :background
      for_n_seconds = 35_000
      Geas::Forum.new :background
    else
      Geas::Forum.new
    end
    future = Time.now + @iteration_step
    future = Colours::PINK+future.strftime('%H:%M:%S').to_s+Colours.rev
    # ===================================================================== #
    # Next, modify the iteration steps in use.
    # ===================================================================== #
    if increase_delay?
      @iteration_step += 1+rand(2)
    elsif use_randomized_delay?
      @iteration_step = INITIAL_DELAY # Reset it here then.
      @iteration_step += rand(180)+31
    end
    counter += @iteration_step
    if show_when_to_retry_next?
      opnn; e 'Retrying in '+simp(@iteration_step.to_s)+
             ' seconds. (At: '+future+')'
    end
    sleep(@iteration_step)
    break if counter > for_n_seconds
  }
end

.set_only_interesting_people(i = GEAS_YAML+'only_interesting_people.yml') ⇒ Object

#

GamesAndRpgParadise::Lpc::Geas::Forum.set_only_interesting_people

#


122
123
124
125
126
127
128
129
130
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 122

def self.set_only_interesting_people(
    i = GEAS_YAML+'only_interesting_people.yml'
  )
  if i.end_with?('.yml') and File.exist?(i)
    i = YAML.load_file(i) # Load the yaml file here.
  end
  i = [i] unless i.is_a? Array
  @only_interesting_people = i
end

.set_wizards(i = FILE_ARRAY_GEAS_WIZARDS) ⇒ Object

#

GamesAndRpgParadise::Lpc::Geas::Forum.set_wizards

#


99
100
101
102
103
104
105
106
107
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 99

def self.set_wizards(
    i = FILE_ARRAY_GEAS_WIZARDS
  )
  if i.end_with?('.yml') and File.exist?(i)
    i = YAML.load_file(i) # Load the yaml file here.
  end
  i = [i] unless i.is_a? Array
  @array_wizads = i
end

.show_when_to_retry_next?Boolean

#

GamesAndRpgParadise::Geas::Forum.show_when_to_retry_next?

#

Returns:

  • (Boolean)


624
625
626
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 624

def self.show_when_to_retry_next?
  SHOW_WHEN_TO_RETRY_NEXT
end

.use_randomized_delay?Boolean

#

GamesAndRpgParadise::Geas.use_randomized_delay?

#

Returns:

  • (Boolean)


522
523
524
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 522

def self.use_randomized_delay?
  USE_RANDOMIZED_DELAY
end

Instance Method Details

#apply_regexObject

#

apply_regex

#


276
277
278
279
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 276

def apply_regex
  data? =~ /#{REGEX}/
  @data = $1.to_s.dup
end

#colourize_logins(i) ⇒ Object

#

colourize_logins

#


735
736
737
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 735

def colourize_logins(i)
  Colours.crimson(i)
end

#colourize_month(i) ⇒ Object

#

colourize_month

#


654
655
656
657
658
659
660
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 654

def colourize_month(i)
  if Object.const_defined? :Colours
    Colours.paleturquoise(i)
  else
    simp(i)
  end
end

#colourize_year(i) ⇒ Object

#

colourize_year

#


742
743
744
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 742

def colourize_year(i)
  Colours.lightsteelblue(i)
end

#commandline?Boolean

#

commandline?

#

Returns:

  • (Boolean)


195
196
197
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 195

def commandline?
  @commandline
end

#data?Boolean Also known as: content?

#

data?

#

Returns:

  • (Boolean)


505
506
507
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 505

def data?
  @data
end

#determine_whether_we_have_found_usersObject

#

determine_whether_we_have_found_users

We ought to find out whether we have found any users.

#


840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 840

def determine_whether_we_have_found_users
  _ = data?
  if _ == 'No registered users' # ok noone was found so we can not do anything.
    nobody_is_currently_logged_in
  elsif _.nil? # Catch the event that the dataset is nil.
    opnn; e 'Something went wrong with the dataset.'
    opnn; e 'We have not found any users.'
    opnn; e 'We will feedback some paths as a consequence of this:'
    opnn; e '  SAVE_FILE -> '+sfile(SAVE_FILE)
    opnn; e '  FILE_GEAS_CHARACTER_EXCLUSION_DATA -> '+
             sfile(FILE_GEAS_CHARACTER_EXCLUSION_DATA)
  else # Could be a bot or a human person here. If it is a
       # human then we will store in a yaml file.
    if _.include? ','
      _ = _.split(',').map(&:strip)
    else
      _ = [_]
    end # From this point it is ab Array. (exclude tag)
    _.reject! {|entry| entry.include? 'Bot' } # Get rid of Bot-entries here.
    _.reject! {|entry| entry.include? '[Spider]' } # Get rid of [Spider]-entries here.
    _.reject! {|entry| entry.include? 'MSNbot Media' } # Get rid of MSNbot Media.
    _.reject! {|entry| entry.include? 'Google Feedfetcher' }
    _.compact!
    if _.empty?
      nobody_is_currently_logged_in
    else
      report_result(_)
    end
  end
end

#feedback_help_optionsObject

#

feedback_help_options (help tag)

All help options will be stored here.

#


460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 460

def feedback_help_options
  e
  cliner {
    e
    opnn; e 'The following options are available:'
    e
    opnn; eparse '    file?'
    opnn; eparse '    show?                    # simply show the full dataset'
    opnn; eparse '    chars?                   # feedback all characters'
    opnn; eparse '    stats?                   # show statistics'
    opnn; eparse '    unique?                  # feedback all unique characters'
    opnn; eparse '    [name of character here] # show when this character last logged in'
    opnn; eparse '    --background             # put this script into the background'
    opnn; eparse '    --do_not_log             # do not log'
    e
  }; e
end

#feedback_unique_charactersObject

#

feedback_unique_characters

Feedback all unique characters through this method.

Invocation example:

geasforum --unique?
#


793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 793

def feedback_unique_characters
  _ = obtain_all_characters # Grab all characters that are logged in.
  # ======================================================================= #
  # Next, get rid of the wizards from that list.
  # ======================================================================= #
  n_wizards = (_ & ARRAY_GEAS_WIZARDS).size
  # ======================================================================= #
  # Next, feedback the dataset that we have obtained.
  # ======================================================================= #
  pp _.sort
  opnn; e 'There are '+sfancy(_.size.to_s)+' characters. '\
         '(Of these are '+simp(n_wizards.to_s)+' wizards)'
  e
  opnn; e 'This derives from a dataset from: (Start - End)'
  opnn; e sfancy(
    '  '+when_did_we_start_to_log?+' - '+when_did_we_end_to_log?
  )
end

#get_last_line_from_fileObject

#

get_last_line_from_file

#


318
319
320
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 318

def get_last_line_from_file
  obtain_dataset.last if obtain_dataset
end

#includes_an_interesting_person?(i) ⇒ Boolean

#

includes_an_interesting_person?

#

Returns:

  • (Boolean)


481
482
483
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 481

def includes_an_interesting_person?(i)
  @only_interesting_people.any? {|entry| i.include? entry }
end

#may_we_store_in_a_logfile?Boolean

#

may_we_store_in_a_logfile?

#

Returns:

  • (Boolean)


498
499
500
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 498

def may_we_store_in_a_logfile?
  @may_we_store_in_a_logfile
end
#

menu

The default input is from the given commandline.

#


538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 538

def menu(i = commandline?) # menu tag
  case i # case tag
  # ======================================================================= #
  # === geasforum --unique?
  # ======================================================================= #
  when 'characters?','feedback_unique_characters','chars?',
       'c?','unique',/unique\??/
    feedback_unique_characters
    exit
  # ======================================================================= #
  # === geasforum --stats?
  # ======================================================================= #
  when 'stats','statistics',/stats\??/,'stat?','stat',
       'status'
    show_statistics
    exit
  # ======================================================================= #
  # === geasforum --background?
  # ======================================================================= #
  when '--background','BACKGROUND'
    run_script_in_the_background 
  when 'HELP','help?','--help','help'
    feedback_help_options
    exit
  when '--do_not_log','nolog','--donotlog'
    @may_we_store_in_a_logfile = false
  when 'editor','OPEN','EDIT'
    open_this_file
    exit
  when 'open','url?','url'
    open_in_browser(url?)
    exit
  when 'file?'
    e file?
    exit
  when 'show?','SHOW'
    show_file
    exit
  else
    @search_for_this_character = i
    if name_exists?(@search_for_this_character) # Ok the name exists, thus obtain all lines with this nick.
      opnn; e 'We found a name-match for the search term `'+
             sfancy(@search_for_this_character)+'`.'
      results = obtain_dataset
      results = results.select {|entry|
        # ================================================================= #
        # We apply a Regex to determine which entries are showing the
        # name in question.
        # ================================================================= #
        entry =~ /#{@search_for_this_character}/i
      }
      # results now contains all of our names that were found.
      report_these_entries(results)
      exit
    end if i
  end
end

#name_exists?(i) ⇒ Boolean

#

name_exists?

Return true or false, depending on whether the name in questions exists or not.

#

Returns:

  • (Boolean)


402
403
404
405
406
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 402

def name_exists?(i)
  i = i.to_s.downcase
  _ = all_characters?.map(&:downcase)
  _.include? i
end

#nobody_is_currently_logged_inObject

#

nobody_is_currently_logged_in

#


284
285
286
287
288
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 284

def nobody_is_currently_logged_in
  if SHALL_WE_REPORT_WHEN_NOBODY_IS_CURRENTLY_LOGGED_IN
    opnn; e 'Nobody is currently logged in.'
  end
end

#notify_the_user_that_the_network_is_unreachableObject

#

notify_the_user_that_the_network_is_unreachable

#


260
261
262
263
264
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 260

def notify_the_user_that_the_network_is_unreachable
  opnn; e 'The network is unreachable.'
  opnn; e 'We will continue to run though - perhaps the network '
          'is available lateron.'
end

#obtain_all_charactersObject Also known as: all_characters?

#

obtain_all_characters

#


425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 425

def obtain_all_characters
  _ = obtain_dataset
  if _
    _.map! {|entry|
      entry = entry.chomp # First, get rid of all newlines.
      splitted = entry.split(/\d\d /)
      if splitted
        last = splitted.last
        last.delete!('.') if last
        if last.include? ',' # If it has more than one entry.
          last = last.split(',').flatten.map(&:strip)
        else
          last = last.strip
        end if last
      end
      last
    }
    _.compact!
    _.flatten!
    _.uniq!
    return _
  else
    opnn; e 'No dataset was found. Perhaps the target directory '+
           'does not exist?'
    opnn; e 'The path would have been:'
    e '  '+sfile(file?) 
    nil
  end
end

#obtain_dataset(this_file = file?) ) ⇒ Object

#

obtain_dataset

Use this to read the lines of our dataset.

#


413
414
415
416
417
418
419
420
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 413

def obtain_dataset(this_file = file?)
  if File.exist? this_file
    dataset = File.readlines(this_file).reject {|entry| entry.chomp.empty? }
  else
    dataset = nil
  end
  return dataset
end

#open_this_fileObject

#

open_this_file

#


371
372
373
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 371

def open_this_file
  esystem 'bluefish '+file?+' &'
end

#opnnObject

#

opnn

#


888
889
890
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 888

def opnn
  Lpc::Geas::Forum.opnn
end

#register_sigintObject

#

register_sigint

#


148
149
150
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 148

def register_sigint
  Signal.trap('SIGINT') { exit }
end

#remove_html_componentObject

#

remove_html_component

#


874
875
876
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 874

def remove_html_component
  @data = Roebe.remove_html[data?]
end

#report_result(i) ⇒ Object

#

report_result

This method will report something such as:

Geas::Forum: 11.08.2015, 21:37:01 `NameOfTheCharacterAppearsHere`.
#


636
637
638
639
640
641
642
643
644
645
646
647
648
649
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 636

def report_result(i)
  i = sanitize_names_of_users(i) # Upcase stuff.
  if i.is_a? Array
    i.each {|name_of_the_character_in_question|
      # =================================================================== #
      # Here we are going to report the character in question.
      # We also "pad" this into a ``.
      # =================================================================== #
      opnn; e return_current_time+
             '`'+sfancy(name_of_the_character_in_question)+'`.'
    }
    save_result(i)
  end
end

#report_these_entries(results) ⇒ Object

#

report_these_entries

Input to this method will be an Array. A line will look such as:

"25.05.2015, 00:51:20 Akulli.\n".

From this line we will also infer the date.

#


678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 678

def report_these_entries(results)
  report_which_dataset_is_used
  # ======================================================================= #
  # Designate the character we look for first.
  # ======================================================================= #
  name_of_the_character = @search_for_this_character.strip
  hash_amount_of_logins = {}
  hash_amount_of_logins.default = 0
  results.map! {|entry|
    entry.gsub(/(#{@search_for_this_character})/i,
      mediumseagreen('\\1'))
  }
  last_day = nil # store which was the last day.
  # ======================================================================= #
  # results is now properly formatted, we can output it.
  # ======================================================================= #
  results.each {|entry|
    # ===================================================================== #
    # Every entry line may look like this:
    #   "08.01.2015, 14:08:07 Aslak.\n"
    # Since we don't need the trailing newline, we chomp it off.
    # ===================================================================== #
    entry.chomp!
    splitted  = entry.split(' ').map(&:strip)
    which_day = splitted.first.delete(',')
    the_day   = which_day.split('.').first
    month     = which_day.split('.')[1]   # The middle part is the month.
    the_year  = which_day.split('.').last # The last part is the year.
    unless the_day == last_day
      # =================================================================== #
      # Store it in the hash.
      # =================================================================== #
      hash_amount_of_logins[the_year+'/'+month] += 1
    end
    last_day = the_day
    e entry
  }
  e
  # ======================================================================= #
  # Next, iterate over the amount of logins.
  # ======================================================================= #
  hash_amount_of_logins.each_pair {|which_year_and_month, n_logins|
    year, which_month = which_year_and_month.split('/')
    name_of_month = (Date::MONTHNAMES[which_month.to_i]).rjust(9)
    e 'In the month '+colourize_month(name_of_month)+
      ' ('+colourize_month(which_month.to_s)+')'+
      ', year '+colourize_year(year)+
      ' '+Colours.mediumseagreen(name_of_the_character.capitalize)+
      Colours.rev+' logged in '+colourize_logins(n_logins.to_s.rjust(2))+
      ' times.'
  }
  e
end

#report_which_dataset_was_usedObject Also known as: report_which_dataset_is_used

#

report_which_dataset_was_used

#


665
666
667
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 665

def report_which_dataset_was_used
  opnn; e 'We used the dataset from `'+sfile(SAVE_FILE)+'`.'
end

#resetObject

#

reset (reset tag)

#


164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 164

def reset
  # ======================================================================= #
  # === @search_for_this_character
  # ======================================================================= #
  @search_for_this_character = nil
  # ======================================================================= #
  # === @initial_delay
  # ======================================================================= #
  @initial_delay = INITIAL_DELAY
  @search_string = SEARCH_STRING # We search for "Registered Users" here.
  @may_we_store_in_a_logfile = false # Right now we won't log.
end

#return_current_timeObject Also known as: current_time?

#

return_current_time

This method will return a String such as “18.07.2015, 11:37:42”.

#


157
158
159
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 157

def return_current_time
  Time.now.strftime('%d.%m.%Y')+', '+Time.now.strftime('%H:%M:%S')+' ' 
end

#revObject

#

rev

#


364
365
366
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 364

def rev
  Colours.rev
end

#runObject

#

run (run tag)

#


895
896
897
898
899
900
901
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 895

def run
  check_against_menu
  scan_remote_website
  apply_regex
  remove_html_component
  determine_whether_we_have_found_users
end

#run_script_in_the_backgroundObject

#

run_script_in_the_background

#


310
311
312
313
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 310

def run_script_in_the_background
  opnn; e 'Now running the script in the background.'
  Process.daemon(true, true)
end

#sanitize_names_of_users(i) ⇒ Object

#

sanitize_names_of_users

#


293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 293

def sanitize_names_of_users(i)
  if i.is_a? Array
    i.map {|entry| sanitize_names_of_users(entry) }
  else
    # ===================================================================== #
    # If the first character is lower cased, upcase it:
    # ===================================================================== #
    if i[0,1] == i[0,1].downcase
      i = i.strip.capitalize
    end
    return i
  end
end

#save_file?Boolean Also known as: file?, yaml_file?

#

save_file?

Wrapper method over the yaml save file.

#

Returns:

  • (Boolean)


490
491
492
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 490

def save_file?
  SAVE_FILE
end

#save_result(this_result = '') ⇒ Object

#

save_result (save tag)

Use this method to save the result into a file.

#


601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 601

def save_result(
    this_result = ''
  )
  save_this_here = ''.dup
  this_result = this_result.join(', ') if this_result.is_a? Array
  unless this_result.empty?
    save_this_here << N if today_is_the_next_day?
    save_this_here << N
    save_this_here << return_current_time
    save_this_here << this_result.chomp
    save_this_here << '.' unless this_result.end_with? '.'
    if includes_an_interesting_person?(save_this_here.delete(N))
      opnn; e 'Now storing `'+sfancy(save_this_here.delete(N))+'` into'
      opnn; e '  `'+sfile(save_file?)+'`.'
      save_this_here << N unless save_this_here.end_with? N
      append_what_into(save_this_here.chomp, save_file?)
    end if may_we_store_in_a_logfile?
  end
end

#scan_remote_websiteObject

#

scan_remote_website

This method will scan the remote website.

It is more efficient to apply .each_line in block form.

#


213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 213

def scan_remote_website
  data = []
  # ======================================================================= #
  # We must protect against the situation when the webforum is not
  # available.
  # ======================================================================= #
  begin
    open(url?) {|remote_handler|
      remote_handler.each_line {|line|
        if line.include? FORUM_IS_UNAVAILABLE
          opnn; e 'The webforum is currently unavailable. '\
                  'Nobody can login right now.'
          break
        elsif line.include? search_string?
          data << line
          break
        end
      }
    }
    set_data(data)
  rescue Errno::EINVAL
    opnn; e 'Errno::EINVAL. Invalid argument to a read() event, most likely File.read().'
  rescue EOFError
    opnn; e 'EOFError. We will continue though.'
  rescue SocketError
    opnn; e 'SocketError. We will continue though.'
  rescue Zlib::BufError
    opnn; e 'Buffer error in Zlib. Very strange error. We will continue though.'
  rescue Net::ReadTimeout, Net::OpenTimeout
    opnn; e 'Net::ReadTimeout or Net::OpenTimeout. We will continue though.'
  rescue Errno::ECONNREFUSED
    opnn; e 'The connection was refused. We will try to continue though.'
  rescue Errno::ETIMEDOUT
    opnn; e 'The network timed out. We will continue though.'
  rescue Errno::ENETUNREACH
    notify_the_user_that_the_network_is_unreachable
    reset_data
  rescue OpenURI::HTTPError => error
    opnn; e 'An OpenURI::HTTPError has happened. We display this'
    opnn; e 'error but we will continue regardless.'
    pp error
  end
end

#search_string?Boolean

#

search_string?

#

Returns:

  • (Boolean)


180
181
182
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 180

def search_string?
  @search_string
end

#set_commandline(i) ⇒ Object

#

set_commandline

#


187
188
189
190
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 187

def set_commandline(i)
  i = i.join if i.is_a? Array
  @commandline = i
end

#set_data(i = nil) ⇒ Object Also known as: reset_data

#

set_data

For now we will keep this as a String.

#


514
515
516
517
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 514

def set_data(i = nil)
  i = i.join if i.is_a? Array
  @data = i
end

#show_fileObject

#

show_file

#


202
203
204
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 202

def show_file
  e Cat[file?]
end

#show_statisticsObject

#

show_statistics

#


325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 325

def show_statistics
  e 'Next we will show the stats for each day.'+N+N
  hash = {}
  obtain_dataset.each {|line|
    next if line.to_s.chomp.empty?
    this_day = line.split(',').first
    splitted = line.split(' ')
    name_of_the_character = splitted.last.delete('.')
    hash[this_day] = [] unless hash.has_key? this_day
    unless hash[this_day].include? name_of_the_character
      hash[this_day] << name_of_the_character.strip.delete('.')
    end
    hash[this_day].sort!
  }
  _ = []
  require 'roebe/classes/wochentag_anzeiger.rb'
  # ======================================================================= #
  # Next report it.
  # ======================================================================= #
  hash.each_pair {|the_day, array|
    size = array.size.to_s
    which_day_is_it = ::Roebe::WochentagAnzeiger[the_day]
    # ===================================================================== #
    # Colourize that day:
    # ===================================================================== #
    which_day_is_it = swarn(which_day_is_it)
    efancy the_day+rev+' ('+which_day_is_it+', '+size+' logged in)'
    e '  '+array.join(', ')
    _ << [the_day, size]
  }
  # ======================================================================= #
  # Also report a dataset that we can feed into R - this is optional though.
  # ======================================================================= #
  pp _
end

#today_is_the_next_day?Boolean

#

today_is_the_next_day? (day tag, next day)

This method will return true or false.

It will return true if the current day is already the next day, and false otherwise.

#

Returns:

  • (Boolean)


383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 383

def today_is_the_next_day?
  return_value = false
  if get_last_line_from_file
    _ = get_last_line_from_file.split(',').first
    last_day_is = Time.parse(_).wday
    if last_day_is == Time.now.wday # In this case, all is fine.
    else
      return_value = true
    end
  end
  return_value
end

#url?Boolean

#

url?

#

Returns:

  • (Boolean)


269
270
271
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 269

def url?
  REMOTE_URL
end

#when_did_we_end_to_log?Boolean

#

when_did_we_end_to_log?

#

Returns:

  • (Boolean)


825
826
827
828
829
830
831
832
833
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 825

def when_did_we_end_to_log?
  dataset = File.readlines(yaml_file?)
  result = dataset.reject {|line|
    line.strip.empty?
  }.last
  regex_to_use = /^(\d\d.\d\d.\d\d\d\d)/
  result =~ regex_to_use
  return $1.to_s.dup
end

#when_did_we_start_to_log?(i = yaml_file?) ) ⇒ Boolean

#

when_did_we_start_to_log?

#

Returns:

  • (Boolean)


815
816
817
818
819
820
# File 'lib/games_and_rpg_paradise/lpc/geas/forum.rb', line 815

def when_did_we_start_to_log?(i = yaml_file?)
  result = File.open(i, &:readline) # This reads in only the first line.
  regex_to_use = /^(\d\d.\d\d.\d\d\d\d)/
  result =~ regex_to_use
  return $1.to_s.dup
end