#!/usr/bin/perl -w use strict; use Data::Dumper; # command for retrieving html sources of an url my $getcmd = "curl"; # "wget -qO-"; # extract a complete list of models from the model list html document: my $html = getsrc_models(); my $alttile = ""; my $alt2tile = ""; my $alt3tile = ""; my $alt4tile = ""; my $alt5tile = ""; my $alt6tile = ""; my $alt7tile = ""; my $alt8tile = ""; my $alt9tile = ""; my @models; while ($html =~ /&model=(.+?)"/ig) { push @models, $1; } # step through each model: foreach my $model (@models) { # retrieve the html source for that particular model's page: $html = getsrc_model($model); $html =~ s///gi; # remove img tags # see if the 'model' contains specs (ie not gui, etc): if ($html =~ /

/i) { my %rec; # retrieve the full title of the model: $html =~ /

(.+?)<\/h1>/i; $rec{'title'} = $1; # get all the specs: while ($html =~ /

(.+): (.+?)<\/p>/gi) { $rec{lc $1} = $2; } # get the description: $html =~ /

.+?<\/p>\s*

\s*(.+?)<\/p>/is; my $desc = $1; $desc =~ s/<.+?>|\n+//g; $rec{'description'} = $desc; # the %rec hash now has keys for all the specs, plus "title" and "description". # for now we just print out the data of the hash: my $processeddata = 'CPU - '.($rec{'cpu'} || 'N/A').' '.($rec{'cpu speed'} || 'N/A').', FPU: '.($rec{'fpu'} || 'N/A').', Level 1 Cache: '.($rec{'level 1 cache'} || 'N/A').', Level 2 Cache: '.($rec{'level 2 cache'} || 'N/A').' RAM - '.'Motherboard: '.($rec{'onboard ram'} || 'N/A').', Max: '.($rec{'maximum ram'} || 'N/A').', Sockets: '.($rec{'ram slots'} || 'N/A').' - '.($rec{'ram type'} || 'N/A').', '.($rec{'ram slots'} || 'N/A').': '.($rec{'minimum ram speed'} || 'N/A').' BUS - '.($rec{'bus speed'} || 'N/A').', Data Path:'.($rec{'data path'} || 'N/A').' DRIVE - CD-Rom: '.($rec{'optical drive'} || 'N/A').', Zip: '.($rec{'zip drive'} || 'N/A').', Floppy: '.($rec{'floppy drive'} || 'N/A').' HD - : '.($rec{'ata bus'} || 'N/A').' '.($rec{'hard disk'} || 'N/A').' SOLD - '.($rec{'introduced'} || 'N/A').' - '.($rec{'terminated'} || 'N/A').' OS - '.($rec{'minimum os'} || 'N/A').' to '.($rec{'minimum os'} || 'N/A').' SLOTS - '.($rec{'slots'} || 'N/A').' ROM - '.($rec{'rom'} || 'N/A').', Gestalt ID: '.($rec{'gestalt id'} || 'N/A').' AUDIO - Input: '.($rec{'audio in'} || 'N/A').', Output: '.($rec{'gestalt id'} || 'N/A').', Speakers: '.($rec{'speakers'} || 'N/A').' VIDEO - Card: '.($rec{'video card'} || 'N/A').' - '.($rec{'video out'} || 'N/A').' Resolutions: '.($rec{'maximum resolution'} || 'N/A').' PORTS - USB: '.($rec{'usb'} || 'N/A').', Firewaire: '.($rec{'firewire'} || 'N/A').' TITLE - '.($rec{'title'} || 'N/A').', Codename: '.($rec{'codename'} || 'N/A').' NETWORKING - Ethernet: '.($rec{'ethernet'} || 'N/A').', Modem: '.($rec{'modem'} || 'N/A').', Bluetooth: '.($rec{'bluetooth'} || 'N/A').' PHYSICAL - Dimensions: '.($rec{'dimensions'} || 'N/A').', Weight: '.($rec{'weight'} || 'N/A').', Power: '.($rec{'power'} || 'N/A').' INFO - '.($rec{'description'} || 'N/A'); my $title = $rec{'title'}; $title =~ s/ /_/g; $title =~ s/-/_/g; $title =~ s/\(//g; $title =~ s/\)//g; $title =~ s/Apple_\/\/\/_&_\/\/\/\+/Apple_III\/Apple_III\+/g; $title =~ s/Apple_\/\//Apple_II/g; $title =~ s/Apple_\/\/+/Apple_II+/g; $title =~ s/Apple_IIc\/IIc\+/Apple_IIc\/Apple_IIc\+/g; $title =~ s/Apple_IIe_Enhanced\/Platinum/Apple_IIe_Enhanced\/Apple_IIe_Platinum/g; $title =~ s/Macintosh_SE\/30/Macintosh_SE_30/g; $title =~ s/PowerBook_DuoDock_Plus\/II/PowerBook DuoDock_Plus\/PowerBook_DuoDock_II/g; $title =~ s/Network_Server_500\/700/Network_Server/g; $title =~ s/PowerBook_1400c\/cs/PowerBook_1400c\/PowerBook_1400cs/g; $title =~ s/iMac_DV\/SE/iMac_DV_SE/g; $title =~ s/PowerBook_G4_1_Ghz\/867_MHz/PowerBook_G4_1_Ghz/g; my @result = split( "/", $title ); foreach(@result){ $_ =~ s/^_//; open(DAT, ">/Users/abey/Desktop/abeytest/test/$_.data") || die("Cannot Open File"); print DAT "$processeddata\n"; close(DAT); $alttile = $_; $alt2tile = $_; $alt3tile = $_; $alt4tile = $_; $alt5tile = $_; $alt6tile = $_; $alt7tile = $_; $alt8tile = $_; $alt9tile = $_; $alttile =~ s/PowerBook_//g; $alt2tile =~ s/PowerBook_/PB_/g; $alt3tile =~ s/Power_Macintosh_//g; $alt4tile =~ s/Power_Macintosh_/PowerMac_/g; $alt5tile =~ s/Macintosh_Quadra_//g; $alt6tile =~ s/Macintosh_Quadra_/Quadra_/g; $alt7tile =~ s/Macintosh_SE_/SE_/g; $alt8tile =~ s/Macintosh_TV_/TV_/g; $alt9tile =~ s/Newton_Message_Pad_/Newton_/g; open(DAT, ">/Users/abey/Desktop/abeytest/test/alttile.data") || die("Cannot Open File"); print DAT "$processeddata\n"; close(DAT); open(DAT, ">/Users/abey/Desktop/abeytest/test/alt2tile.data") || die("Cannot Open File"); print DAT "$processeddata\n"; close(DAT); open(DAT, ">/Users/abey/Desktop/abeytest/test/alt3tile.data") || die("Cannot Open File"); print DAT "$processeddata\n"; close(DAT); open(DAT, ">/Users/abey/Desktop/abeytest/test/alt4tile.data") || die("Cannot Open File"); print DAT "$processeddata\n"; close(DAT); open(DAT, ">/Users/abey/Desktop/abeytest/test/alt5tile.data") || die("Cannot Open File"); print DAT "$processeddata\n"; close(DAT); open(DAT, ">/Users/abey/Desktop/abeytest/test/alt6tile.data") || die("Cannot Open File"); print DAT "$processeddata\n"; close(DAT); open(DAT, ">/Users/abey/Desktop/abeytest/test/alt7tile.data") || die("Cannot Open File"); print DAT "$processeddata\n"; close(DAT); open(DAT, ">/Users/abey/Desktop/abeytest/test/alt8tile.data") || die("Cannot Open File"); print DAT "$processeddata\n"; close(DAT); open(DAT, ">/Users/abey/Desktop/abeytest/test/alt9tile.data") || die("Cannot Open File"); print DAT "$processeddata\n"; close(DAT); } open(DAT, ">/Users/abey/Desktop/abeytest/test/$model.data") || die("Cannot Open File"); print DAT "$processeddata\n"; close(DAT); my $codename = ($rec{'codename'} || 'NA'); my @result2 = split( ", ", $codename ); foreach(@result2){ $_ =~ s/ /_/g; $_ =~ s/-/_/g; $_ =~ s/\(//g; $_ =~ s/\)//g; $_ =~ s/\//_/g; open(DAT, ">/Users/abey/Desktop/abeytest/test/$_.data") || die("Cannot Open File"); print DAT "$processeddata\n"; close(DAT); } } } sub getsrc_models { #return `$getcmd "http://www.apple-history.com/frames/nav_list.php?page=recent_changes&model=&sort=&performa="`; return `cat html/_models.html`; } sub getsrc_model { my $model = shift; #return `$getcmd "http://www.apple-history.com/frames/body.php?page=gallery&model=$model`; return `cat html/$model.html`; }