root/HTTP-MobileAgent/trunk/bin/makedocomomap

Revision 890 (checked in by miyagawa, 17 years ago)

version 0.10

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
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/p_s/imode/spec/ryouiki.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/\n+/\n/g;
16     my $re = regexp();
17     my %map;
18     while ($html =~ /$re/gs) {
19         my($model, $width, $height, $color, $depth) = ($1, $2, $3, $4, $5);
20         $map{$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     printf <<'TEMPLATE', Data::Dumper->Dump([ $map ], [ qw(DisplayMap) ]);
39 package HTTP::MobileAgent::DoCoMoDisplayMap;
40 # This file is autogenerated by makedocomomap
41 # in HTTP-MobileAgent distribution
42
43 use strict;
44 require Exporter;
45 use base qw(Exporter);
46
47 use vars qw(@EXPORT_OK $DisplayMap);
48 @EXPORT_OK = qw($DisplayMap);
49
50 %s
51
52 1;
53 TEMPLATE
54     ;
55     if ($overwrite) {
56         close MAP;
57     }
58 }
59
60 sub regexp {
61     return <<'RE';
62 <TD><FONT SIZE="2">([A-Z]+\d+\w*)</FONT></TD>
63 <TD><FONT SIZE="2">.*?</FONT></TD>
64 <TD><FONT SIZE="2">.*?</FONT></TD>
65 <TD><FONT SIZE="2">(.*?)¡ß(.*?)</FONT></TD>
66 <TD><FONT SIZE="2">.*?</FONT></TD>
67 <TD><FONT SIZE="2">(Çò¹õ|¥«¥é¡Œ)(\d+)(?:¿§|³¬ÄŽ)</FONT></TD>
68 RE
69     ;
70 }
Note: See TracBrowser for help on using the browser.