Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Lookup seagate hard drives by model number

by diotalevi (Canon)
on Jan 03, 2005 at 00:53 UTC ( [id://418848]=sourcecode: print w/replies, xml ) Need Help??
Category: Web Stuff
Author/Contact Info
Description:

Lookup Seagate hard drives by model number.

$ bin/lookup_seagatehd ST118202FC ST336752FC ST150176FC Desc=ST-118202FC Fibre Channel FC-AL, Dual Port (Cheetah 18) Capacity=18.2 RPM=10000 Access time=6 Desc=ST-336752FC Fibre Channel FC-AL, Dual Port (Cheetah X15 36LP) Capacity=36.7 RPM=15000 Access time=3.6 Desc=ST-150176FC Fibre Channel FC-AL, Dual Port (Barracuda 50) Capacity=50.01 RPM=7200 Access time=7.6
use strict;
use warnings;
use WWW::Mechanize ();
use String::Approx 'adist';

main( @ARGV );
exit;

sub main {
  initialize( @_ );

  for my $part_number ( @_ ) {
    print part_spec( $part_number ) . "\n";
  }
}

sub initialize {

}

sub part_spec {
  my $part_number = shift;
  my ( $bare_number ) = $part_number =~ /^(ST\d+)/;

  my $www = WWW::Mechanize->new;
  $www->get( 'http://www.seagate.com/support/disc/' );
  $www->submit_form( form_number => 2,
                     fields => { modelcode => $bare_number } );

  my $spec_page;
  for my $test ( qr/.support.disc.specs.+$part_number/i,
                 qr/.support.disc.specs.+$bare_number/i ) {
    my @candidates = $www->find_all_links( url_regex => $test );
    if ( 1 == @candidates ) {
      $spec_page = $candidates[0];
      last;
    }
    elsif ( @candidates ) {
      my @dists
        = map adist( lc( $part_number ), lc( $_->url ) ),
          @candidates;
      $spec_page
        = $candidates[ ( sort { $dists[$a] <=> $dists[$b] }
                         0 .. $#dists )[ 0 ] ];
      last;
    }
  }

  $www->get( $spec_page->URI );

  my ( $capacity, $rpm, $access_time, $desc )
    = $www->content =~ /\b ([\d.]+) \s* GB  .+?
                        \b (\d+)    \s* rpm .+?
                        \b ([\d.]+) \s* ms  .+?
                        ((?-s:ST-\d+.+))/xs;

  return
    "Desc=$desc\n"
    . "Capacity=$capacity\n"
    . "RPM=$rpm\n"
    . "Access time=$access_time\n";
}

sub render_html {
  require HTML::FormatText;
  my $html = shift;

  return HTML::FormatText->format_string( $html );
}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://418848]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-03-29 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found