Class: GamesAndRpgParadise::Gamebooks::DownloadGamebook
- Includes:
- Base::ExtensionsForAGamebook
- Defined in:
- lib/games_and_rpg_paradise/gamebooks/download_gamebook/download_gamebook.rb
Overview
GamesAndRpgParadise::Gamebooks::DownloadGamebook
Constant Summary collapse
- BASE_URL =
#
BASE_URL
#
BASE_URL = ‘www.projectaon.org/en/xhtml/lw/01fftd/’ BASE_URL = ‘www.projectaon.org/en/xhtml/lw/02fotw/’#sect1.htm’ BASE_URL = ‘www.projectaon.org/en/xhtml/lw/03tcok/’ BASE_URL = ‘www.projectaon.org/en/xhtml/lw/04tcod/’ BASE_URL = ‘www.projectaon.org/en/xhtml/lw/05sots/’ BASE_URL = ‘www.projectaon.org/en/xhtml/lw/06tkot/’ BASE_URL = ‘www.projectaon.org/en/xhtml/lw/07cd/kaiwisdm.htm’
'https://www.projectaon.org/en/xhtml/lw/08tjoh/kaiwisdm.htm'
- REGEX_FOR_IMAGES =
/<img .+ src="(.+.png)".+\/>/
- START_POINT =
#
START_POINT
Designate at which remote URL subpage to start.
#
1
- END_POINT =
#
END_POINT
#
350
Constants included from Base::ExtensionsForAGamebook
Base::ExtensionsForAGamebook::DIRECTORY_FOR_THE_GAMEBOOKS
Constants included from CommonExtensions
CommonExtensions::CONTROL_C_CODE, CommonExtensions::N
Constants included from Base::Extensions::Colours
Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS
Instance Method Summary collapse
-
#all_images? ⇒ Boolean
# === all_images? ========================================================================= #.
-
#append_content_from_this_file_onto_the_array_containing_all_unique_images(yaml_file_containing_all_downloaded_images = @yaml_file_containing_all_downloaded_images) ⇒ Object
# === append_content_from_this_file_onto_the_array_containing_all_unique_images ========================================================================= #.
-
#consider_creating_a_local_HTML_file_containing_all_images ⇒ Object
# === consider_creating_a_local_HTML_file_containing_all_images.
-
#do_batch_download ⇒ Object
# === do_batch_download ========================================================================= #.
-
#do_store_the_images ⇒ Object
# === do_store_the_images ========================================================================= #.
-
#initialize(i = ARGV, run_already = true) ⇒ DownloadGamebook
constructor
# === initialize ========================================================================= #.
-
#menu(i = commandline_arguments? ) ⇒ Object
# === menu (menu tag) ========================================================================= #.
-
#remote_URL? ⇒ Boolean
# === remote_URL? ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#run ⇒ Object
# === run ========================================================================= #.
-
#show_help ⇒ Object
# === show_help (help tag).
Methods included from Base::ExtensionsForAGamebook
#available_gamebooks?, #io_download, #roll_this_die, use_gtk?, #use_gtk?, #wget, #yaml_gamebooks_dir?
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, #opnn, #project_base_directory?, #project_image_directory?, #project_yaml_directory?, #rds, #register_sigint, #remove_this_directory, #rename_file, #reset_the_internal_hash, #return_pwd, #return_today, #touch_file, #wrap, #write_what_into
Methods included from Base::Extensions::Colours
ecomment, #efancy, #eparse, #forestgreen, #gold, #grey, #lightblue, #mediumseagreen, #mediumslateblue, #peru, #rev, sdir, sfancy, #sfile, simp, #teal, #yellow
Constructor Details
#initialize(i = ARGV, run_already = true) ⇒ DownloadGamebook
#
initialize
#
63 64 65 66 67 68 69 70 |
# File 'lib/games_and_rpg_paradise/gamebooks/download_gamebook/download_gamebook.rb', line 63 def initialize( i = ARGV, run_already = true ) set_commandline_arguments(i) reset run if run_already end |
Instance Method Details
#all_images? ⇒ Boolean
#
all_images?
#
95 96 97 |
# File 'lib/games_and_rpg_paradise/gamebooks/download_gamebook/download_gamebook.rb', line 95 def all_images? @internal_hash[:array_downloaded_images] end |
#append_content_from_this_file_onto_the_array_containing_all_unique_images(yaml_file_containing_all_downloaded_images = @yaml_file_containing_all_downloaded_images) ⇒ Object
#
append_content_from_this_file_onto_the_array_containing_all_unique_images
#
215 216 217 218 219 220 |
# File 'lib/games_and_rpg_paradise/gamebooks/download_gamebook/download_gamebook.rb', line 215 def append_content_from_this_file_onto_the_array_containing_all_unique_images( yaml_file_containing_all_downloaded_images = @yaml_file_containing_all_downloaded_images ) @internal_hash[:array_unique_images] << YAML.load_file(yaml_file_containing_all_downloaded_images) @internal_hash[:array_unique_images].flatten! end |
#consider_creating_a_local_HTML_file_containing_all_images ⇒ Object
#
consider_creating_a_local_HTML_file_containing_all_images
This method will delegate towards the cyberweb-project.
#
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/games_and_rpg_paradise/gamebooks/download_gamebook/download_gamebook.rb', line 227 def consider_creating_a_local_HTML_file_containing_all_images _ = @internal_hash[:array_unique_images] unless _.empty? begin require 'open' rescue LoadError; end begin require 'cyberweb/utility_scripts/images_to_html/images_to_html.rb' webpage = Cyberweb::ImagesToHtml.new(ARGV, :do_not_run_yet) webpage.this_directory_contains_all_images = false # =================================================================== # # Feed the images to the class next: # =================================================================== # webpage.array_work_on_these_files << @internal_hash[:array_unique_images] webpage.array_work_on_these_files.flatten! result = webpage.the_two_last_actions if File.file?(result) Open.in_browser(result) if Object.const_defined?(:Open) end rescue LoadError; end end end |
#do_batch_download ⇒ Object
#
do_batch_download
#
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/games_and_rpg_paradise/gamebooks/download_gamebook/download_gamebook.rb', line 128 def do_batch_download cd(log_dir?) # ======================================================================= # # Next, this is hardcoded for now. At a later time we may have to # make this more flexible and dynamic. # ======================================================================= # _ = remote_URL? if _.end_with? '.htm' _ = "#{File.dirname(_)}/" end # ======================================================================= # # Build up the path, such as /home/x/Temp/rpg_paradise/lone_wolf_19/. # ======================================================================= # new_directory = File.absolute_path( "lone_wolf_#{File.basename(_).to_i.to_s}" ) mkdir_then_cd_into_it(new_directory) @yaml_file_containing_all_downloaded_images = File.absolute_path( 'downloaded_images.yml' ) unless File.file? @yaml_file_containing_all_downloaded_images e "#{rev}Creating a file at "\ "#{sfile(@yaml_file_containing_all_downloaded_images)}#{rev}." touch_file(@yaml_file_containing_all_downloaded_images) end if File.file?(@yaml_file_containing_all_downloaded_images) and !File.empty?(@yaml_file_containing_all_downloaded_images) append_content_from_this_file_onto_the_array_containing_all_unique_images(@yaml_file_containing_all_downloaded_images) end e e "#{rev}Starting batch download now:" e START_POINT.upto(END_POINT) {|entry| use_this_URL = _+'sect'+entry.to_s+'.htm' e "Downloading #{::Colours.steelblue(use_this_URL)} next:" begin begin local_path = io_download( use_this_URL ) e "#{rev}Stored in `#{sfile(local_path)}#{rev}`." # ================================================================= # # Check if this has an image. # ================================================================= # dataset = File.read(local_path) scanned = dataset.scan(REGEX_FOR_IMAGES).flatten e 'Possible unique images:' e scanned.each {|this_image| remote_image = File.dirname(use_this_URL)+'/'+this_image unless @internal_hash[:array_unique_images].include? remote_image @internal_hash[:array_unique_images] << remote_image e ::Colours.orange(" #{remote_image}") end } e rescue Net::OpenTimeout do_store_the_images end rescue LoadError => error e 'An error occurred for entry '+sfancy(entry)+'.' e pp error e e "#{rev}The remote URL was `#{sfancy(use_this_URL)}#{rev}`." e 'The number was: '+ use_this_URL.scan(/d+/).flatten.first.to_s do_store_the_images exit end } end |
#do_store_the_images ⇒ Object
#
do_store_the_images
#
204 205 206 207 208 209 210 |
# File 'lib/games_and_rpg_paradise/gamebooks/download_gamebook/download_gamebook.rb', line 204 def do_store_the_images e 'Dumping all files into the local file.' write_what_into( all_images?, @yaml_file_containing_all_downloaded_images ) end |
#menu(i = commandline_arguments? ) ⇒ Object
#
menu (menu tag)
#
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/games_and_rpg_paradise/gamebooks/download_gamebook/download_gamebook.rb', line 253 def ( i = commandline_arguments? ) if i.is_a? Array i.each {|entry| (entry) } else case i # ===================================================================== # # === download_gamebook --help # ===================================================================== # when /help$/i show_help exit # ===================================================================== # # === download_gamebook lone-wolf-4 # ===================================================================== # when /^-?-?lone(-|_)?wolf-?(\d+)$/ # === $2 _ = $2.to_s.dup opne "Now attempting to download lone wolf dataset for book ##{_}." # =================================================================== # # We must find the corresponding URL: # =================================================================== # @internal_hash[:remote_URL] = GamesAndRpgParadise::Gamebook::LoneWolf.map_number_to_remote_URL(_) opne "#{rev}The remote URL is at: #{steelblue(@internal_hash[:remote_URL])}" end end end |
#remote_URL? ⇒ Boolean
#
remote_URL?
#
121 122 123 |
# File 'lib/games_and_rpg_paradise/gamebooks/download_gamebook/download_gamebook.rb', line 121 def remote_URL? @internal_hash[:remote_URL] end |
#reset ⇒ Object
#
reset (reset tag)
#
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/games_and_rpg_paradise/gamebooks/download_gamebook/download_gamebook.rb', line 75 def reset super() reset_the_internal_hash # ======================================================================= # # === :array_downloaded_images # ======================================================================= # @internal_hash[:array_downloaded_images] = [] # ======================================================================= # # === :remote_URL # ======================================================================= # @internal_hash[:remote_URL] = BASE_URL # ======================================================================= # # === @internal_hash[:array_unique_images] # ======================================================================= # @internal_hash[:array_unique_images] = [] end |
#run ⇒ Object
#
run
#
284 285 286 287 288 |
# File 'lib/games_and_rpg_paradise/gamebooks/download_gamebook/download_gamebook.rb', line 284 def run do_batch_download consider_creating_a_local_HTML_file_containing_all_images end |
#show_help ⇒ Object
#
show_help (help tag)
Usage example:
downloadgamebook --help
#
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/games_and_rpg_paradise/gamebooks/download_gamebook/download_gamebook.rb', line 107 def show_help e 'Available options are:' e 1.upto(24).each {|entry| e ' --lone-wolf-'+entry.to_s.ljust(2, ' ')+ ' # download gamebook number '+entry.to_s.rjust(2, ' ')+ ' of the lone wolf series' } e end |