Class: Cyberweb::DownloadAllImagesFromThisWebsite
- Defined in:
- lib/cyberweb/utility_scripts/download_all_images_from_this_website.rb
Overview
Cyberweb::DownloadAllImagesFromThisWebsite
Constant Summary
Constants inherited from Base
Base::HOME_DIRECTORY_OF_THE_USER_X, Base::NAMESPACE
Instance Method Summary collapse
-
#create_the_images_directory ⇒ Object
# === create_the_images_directory ========================================================================= #.
-
#cweb ⇒ Object
# === cweb ========================================================================= #.
-
#initialize(commandline_arguments = ARGV, run_already = true) ⇒ DownloadAllImagesFromThisWebsite
constructor
# === initialize ========================================================================= #.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#run ⇒ Object
# === run ========================================================================= #.
-
#tomato(i) ⇒ Object
# === tomato ========================================================================= #.
-
#work_on_these_images(these_images) ⇒ Object
# === work_on_these_images.
Methods inherited from Base
#be_verbose, #be_verbose?, #cascading_style_sheets_directory?, #cd, #commandline_mode?, #copyright?, #css_comment, #delete_directory, #do_toggle, #e, #echo_raw, #filename?, #full_path_to_image_directory?, #html_colours?, #html_image, #htmlentities, #img_dir?, #infer_the_namespace, #initialize_the_configuration, #is_a_file?, #is_a_video_file?, #is_an_image_file?, #is_on_roebe?, #last_tag_used?, #last_tag_used_first_element?, #last_tag_used_id?, #mkdir, #mode?, #namespace?, #open_in_browser, #opne, #opnn, #remove_comments_from_this_string_but_preserve_CSS_rules, #remove_html, #return_all_directories, #return_date, #return_program_name, #return_pwd, #ruby_header?, #server_base_directory?, #set_commandline_mode, #set_last_tag_used, #update_the_image_directory, #use_this_relative_directory_for_custom_images?, #www_mode?
Methods included from BaseModule::FileRelatedFunctionality
#copy_this_file, #cpr, #delete_file, #filename_without_extension?, #read_file_via_utf8_encoding
Methods included from BaseModule
#attach_these_constants, #base_dir?, #beautiful_url, #cd, #create_the_internal_hash, #doctype?, #ee, #ensure_main_encoding, #esystem, #html_templates, #initialize_the_config_if_the_config_hash_is_empty, #internal_hash?, #log_dir?, #no_http, #random_alphabet_characters, #rarrow?, #rds, #remove_comments_from_this_string, #remove_numbers, #require_the_html_templates, #require_these, #return_file_size_in_kb_of, #return_html_comment, #ruby_sitelib_dir?, #sanitize_this_id, #server_base_directory?, #string_remote_image, #today?, #try_to_require_rack, #try_to_require_the_open_gem, #write_what_into
Methods included from BaseModule::ContentType
#content_type_is_html, #content_type_is_jpeg, #content_type_is_json, #content_type_is_plain_text
Methods included from BaseModule::CommandlineArguments
#append_to_the_commandline_arguments, #commandline_arguments?, #first_argument?, #parse_these_commandline_arguments, #second_argument?, #set_commandline_arguments
Methods included from BaseModule::Colours
#all_html_colours, #lightgreen, #rev, #sdir, #sfancy, #sfile, #simp, #steelblue
Constructor Details
#initialize(commandline_arguments = ARGV, run_already = true) ⇒ DownloadAllImagesFromThisWebsite
#
initialize
#
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cyberweb/utility_scripts/download_all_images_from_this_website.rb', line 26 def initialize( commandline_arguments = ARGV, run_already = true ) reset set_commandline_arguments( commandline_arguments ) run if run_already end |
Instance Method Details
#create_the_images_directory ⇒ Object
#
create_the_images_directory
#
53 54 55 |
# File 'lib/cyberweb/utility_scripts/download_all_images_from_this_website.rb', line 53 def create_the_images_directory mkdir 'images/' unless File.directory?('images/') end |
#cweb ⇒ Object
#
cweb
#
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/cyberweb/utility_scripts/download_all_images_from_this_website.rb', line 92 def cweb webpage = Cyberweb::ImagesToHtml.new([], :do_not_run_yet) { :use_jquery } target_directory = File.absolute_path( File.basename(Dir.pwd).downcase+'.html' ) pp target_directory pp target_directory pp target_directory pp target_directory exit webpage.set_store_where(target_directory) webpage.set_images( Dir['*.png'] ) puts 'Next creating the following page: '+webpage.stored_where? webpage.scan_for_images_in_this_directory :return_pwd webpage.save_what_to end |
#reset ⇒ Object
#
reset
#
40 41 42 43 |
# File 'lib/cyberweb/utility_scripts/download_all_images_from_this_website.rb', line 40 def reset super() infer_the_namespace end |
#run ⇒ Object
#
run
#
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/cyberweb/utility_scripts/download_all_images_from_this_website.rb', line 114 def run target = first_argument? create_the_images_directory # ======================================================================= # # The next method will save into a file. # ======================================================================= # array = Cyberweb.download_webpage(target) _ = array.first regex_to_use = # /<img.+src="([A-Za-z0-9\/:\.-]+)/ # See: https://rubular.com/r/vRogtVrSuDYd8f /<img ?[A-Za-z"=]* ?src="(.+\.[a-z]{3,4})".*>/ # See: https://rubular.com/r/XGcBGjyezWh4jO scanned = _.scan(regex_to_use) flattened = scanned.flatten cd 'images' # Enter our target directory. work_on_these_images(flattened) cweb end |
#tomato(i) ⇒ Object
#
tomato
#
48 |
# File 'lib/cyberweb/utility_scripts/download_all_images_from_this_website.rb', line 48 def tomato(i); ::Colours.tomato(i); end |
#work_on_these_images(these_images) ⇒ Object
#
work_on_these_images
Before this method is called, a directory called images/ will be created by this class. So all downloads will go into that directory.
#
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/cyberweb/utility_scripts/download_all_images_from_this_website.rb', line 64 def work_on_these_images(these_images) f rev+'Working on `'+ ::Colours.steelblue(first_argument?)+ rev+'` next.' these_images.each {|this_image| f 'The current image that is investigated is: '+tomato(this_image.to_s) uri = URI(first_argument?) # new_url = uri.scheme+'://'+uri.host+'/'+ # this_image # esystem 'wget '+new_url f rev+'This image will next be downloaded into the following '\ 'directory: `'+sdir(return_pwd)+rev+'`.' run_this_command = 'wget '.dup run_this_command << uri.scheme+':' run_this_command << '/' unless this_image.start_with? '/' run_this_command << '/' unless this_image.start_with? '//' run_this_command << this_image f ::Colours.tomato(run_this_command) f system run_this_command f } end |