Skip to content

Mechanize-Progressbar provides ProgressBar for Mechanize#get and Link#click..

License

Notifications You must be signed in to change notification settings

kitamomonga/Mechanize-ProgressBar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mechanize-progressbar

Mechanize-Progressbar provides ProgressBar when you use Mechanize#get/Page#click. HTTP response only. HTTP requests are not supported.

you can do

script:

require 'mechanize'
require 'mechanize/progressbar'
agent = Mechanize.new
agent.progressbar{ agent.get(large_file) }

$stderr output:

http://host/large_file.zip
15% |ooooooo                        | 135.2KB  21.9KB/s ETA:  00:00:10

Requirements

  • Ruby 1.8.6 or later

  • recent Rubygems

  • Mechanize gem (1.0.0, 2.0)

  • ProgressBar gem

USAGE

Get file in Mechanize#progressbar block.

require 'mechanize'
require 'mechanize/progressbar'
agent = Mechanize.new
agent.progressbar{ agent.get(large_file) }

Link#click also works.

agent = Mechanize.new
agent.get(some_page)
agent.progressbar do
  agent.page.link_with(:text => 'download here').click
end

config ProgressBar

If you want to modify ProgressBar object, set options to argument.

pbar = ProgressBar.new(@title, @total, @out)
pbar.format = @format
pbar.format_arguments = @format_arguments

is

agent = Mechanize.new
agent.progressbar(
  :title => @title,
  :total => @total,
  :out => @out,
  :format => @format,
  :format_arguments => @format_arguments
){ agent.get(large_file) }

Mechanize-Progressbar prints the URL to $stderr before progressbar.

script:

agent.progressbar{ agent.get(large_file) }

output:

http://uri.host/large_file.zip
15% |ooooo                           | 135.2KB  21.9KB/s ETA:  00:00:10

If you do not want the “two-line mode”, set (:single => true).

script:

agent.progressbar(:single => true){ agent.get(large_file) }

output:

uri.host:   15% |ooo                 | 135.2KB  21.9KB/s ETA:  00:00:10

When Mechanize Logger output is same to ProgressBar (i.e, agent.log=Logger.new($stderr)), Mechanize::ProgressBar stops showing socket read log.

script:

agent.log = Logger.new($stderr)
agent.progressbar{ agent.get(large_file) }

output:

http://uri.host/large_file.zip
100% |ooooooooooooooooooooooooooooooo| 1024.0KB  21.9KB/s Time:  00:00:20
D, [...] DEBUG -- : Read 102400 bytes

LARGE FILE DOWNLOAD NOTE

Mechanize keeps all the got files as String object. When you get the five 100MB files, Mechanize uses at least 500MB memory.

If you wish to run Mechanize with minimum memory usage, try

agent.max_history = 1

Licence

MIT

alike Mechanize.

Author

kitamomonga kitamomonga@gmail.com d.hatena.ne.jp/kitamomonga/ (Japanese)

About

Mechanize-Progressbar provides ProgressBar for Mechanize#get and Link#click..

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages