| 1 | #!/usr/bin/perl -w |
|---|
| 2 | use strict; |
|---|
| 3 | use FindBin; |
|---|
| 4 | use Jcode; |
|---|
| 5 | use LWP::Simple; |
|---|
| 6 | use Data::Dumper; |
|---|
| 7 | use HTTP::MobileAgent; |
|---|
| 8 | |
|---|
| 9 | my $URL = 'http://www.nttdocomo.co.jp/service/imode/make/content/spec/screen_area/index.html'; |
|---|
| 10 | |
|---|
| 11 | do_task(@ARGV); |
|---|
| 12 | |
|---|
| 13 | sub do_task { |
|---|
| 14 | my $html = Jcode->new(get($URL))->tr('��-��', '0-9')->euc; |
|---|
| 15 | $html =~ s/(?:\r?\n)+/\n/g; |
|---|
| 16 | my $re = regexp(); |
|---|
| 17 | my %map; |
|---|
| 18 | while ($html =~ /$re/igs) { |
|---|
| 19 | my($model, $width, $height, $color, $depth) = ($1, $2, $3, $4, $5); |
|---|
| 20 | $map{uc($model)} = { |
|---|
| 21 | width => $width, |
|---|
| 22 | height => $height, |
|---|
| 23 | color => $color eq '���顼', |
|---|
| 24 | depth => $depth, |
|---|
| 25 | }; |
|---|
| 26 | } |
|---|
| 27 | my $overwrite = $ARGV[0] && $ARGV[0] eq '-o'; |
|---|
| 28 | output_code(\%map, $overwrite); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | sub output_code { |
|---|
| 32 | my($map, $overwrite) = @_; |
|---|
| 33 | if ($overwrite) { |
|---|
| 34 | open MAP, "> $FindBin::Bin/../lib/HTTP/MobileAgent/DoCoMoDisplayMap.pm" or die $!; |
|---|
| 35 | select MAP; |
|---|
| 36 | } |
|---|
| 37 | $Data::Dumper::Indent = 1; |
|---|
| 38 | $Data::Dumper::Terse = 1; |
|---|
| 39 | printf <<'TEMPLATE', Data::Dumper->Dump([ $map ]); |
|---|
| 40 | package HTTP::MobileAgent::DoCoMoDisplayMap; |
|---|
| 41 | # This file is autogenerated by makedocomomap |
|---|
| 42 | # in HTTP-MobileAgent distribution |
|---|
| 43 | |
|---|
| 44 | use strict; |
|---|
| 45 | require Exporter; |
|---|
| 46 | use base qw(Exporter); |
|---|
| 47 | |
|---|
| 48 | use vars qw(@EXPORT_OK $DisplayMap); |
|---|
| 49 | @EXPORT_OK = qw($DisplayMap); |
|---|
| 50 | |
|---|
| 51 | BEGIN { |
|---|
| 52 | if ($ENV{DOCOMO_MAP}) { |
|---|
| 53 | eval q{ |
|---|
| 54 | require XML::Simple; |
|---|
| 55 | my $xml = XML::Simple->new; |
|---|
| 56 | my $map = $xml->XMLin($ENV{DOCOMO_MAP}); |
|---|
| 57 | if ($map->{terminal}) { |
|---|
| 58 | # new layout |
|---|
| 59 | for my $terminal (@{$map->{terminal}}) { |
|---|
| 60 | my $model = delete $terminal->{model}; |
|---|
| 61 | $DisplayMap->{$model} = $terminal; |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | else { |
|---|
| 65 | # old layout |
|---|
| 66 | $DisplayMap = $map; |
|---|
| 67 | } |
|---|
| 68 | }; |
|---|
| 69 | warn "using normal hash map: $@" if $@; |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | $DisplayMap ||= %s; |
|---|
| 74 | |
|---|
| 75 | 1; |
|---|
| 76 | TEMPLATE |
|---|
| 77 | ; |
|---|
| 78 | if ($overwrite) { |
|---|
| 79 | close MAP; |
|---|
| 80 | } |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | sub regexp { |
|---|
| 84 | return <<'RE'; |
|---|
| 85 | <td><span class="txt">([A-Z]+\d+\w*\+?).*?</span></td> |
|---|
| 86 | <td><span class="txt">.*?(?:</span></td>)? |
|---|
| 87 | <td><span class="txt">.*?(?:</span></td>)? |
|---|
| 88 | <td><span class="txt">.*?(\d+)��\d+).*?</span></td> |
|---|
| 89 | <td>.*?</td> |
|---|
| 90 | <td><span class="txt">(����顼)(?:.*?)(\d+)(?:��|��Ĵ)</span></td> |
|---|
| 91 | RE |
|---|
| 92 | ; |
|---|
| 93 | } |
|---|