updated git and svn scripts
[xrzperl.git] / urlrule_new
blob075f62a13fa12b4de27202d91a8188d5e28446c5
1 #!/usr/bin/perl -w
2 ###APPNAME: urlrule_new
3 ###APPAUTHOR: xiaoranzzz
4 ###APPDATE: Sat Mar 22 22:56:33 2008
5 ###APPVER: 0.1
6 ###APPDESC: create new url rule
7 ###APPUSAGE: URL [0-5]
8 ###APPEXAMPLE: urlrule_new http://www.shuku.net/novels/gulong/bianlang/bianlang.html 2
9 ###APPOPTION:
10 use strict;
11 use lib $ENV{XR_PERL_MODULE_DIR};
12 use MyPlace::Script::Usage qw/help_even_empty/;
14 exit 0 if(help_even_empty($0,@ARGV));
16 use MyPlace::ColorPrint;
17 use MyPlace::URLRule qw/parse_rule/;
19 my %rule = %{parse_rule(@ARGV)};
20 my $url=$rule{url};
21 my $level=$rule{level};
22 my $source=$rule{source};
25 if(-f $source) {
26 app_message("Rule for $url exists,opened for editing instead\n");
27 system("r-vim \"$source\"&");
28 exit 0;
31 my $date=localtime();
32 open VIMED,"|-","r-vim -c 'file $source' - ";
33 print VIMED <<"HEAD";
34 #!/usr/bin/perl -w
35 #$url
36 #$date
37 use strict;
40 HEAD
42 print VIMED <<'FUNC';
44 =method1
45 sub apply_rule {
46 return (
47 '#use quick parse'=>1,
48 'data_exp'=>undef,
49 'data_map'=>undef,
50 'pass_exp'=>undef,
51 'pass_map'=>undef,
52 'pass_name_map'=>undef,
53 'pages_exp'=>undef,
54 'pages_map'=>undef,
55 'pages_pre'=>undef,
56 'pages_suf'=>undef,
57 'pages_start'=>undef,
58 'title_exp'=>undef,
59 'title_map'=>undef,
60 'charset'=>undef
63 =cut
65 =method2
66 use MyPlace::Curl;
67 #use MyPlace::HTML;
69 sub _process {
70 my ($url,$rule,$html) = @_;
71 my $title = undef;
72 my @data;
73 my @pass_data;
74 #my @html = split(/\n/,$html);
75 return (
76 count=>scalar(@data),
77 data=>[@data],
78 pass_count=>scalar(@pass_data),
79 pass_data=>[@pass_data],
80 base=>$url,
81 no_subdir=>1,
82 work_dir=>$title,
86 sub apply_rule {
87 my $url = shift(@_);
88 my $rule = shift(@_);
89 my $http = MyPlace::Curl->new();
90 my (undef,$html) = $http->get($url);
91 return &_process($url,$rule,$html,@_);
93 =cut
96 FUNC
97 print VIMED <<'USAGE';
99 __END__
101 #================================================================
102 # apply_rule will be called with ($RuleBase,%Rule),the result returned have these meaning:
103 # $result{base} : Base url to build the full url
104 # $result{work_dir} : Working directory (will be created if not exists)
105 # $result{data} : Data array extracted from url,will be passed to $result{action}(see followed)
106 # $result{action} : Command which the $result{data} will be piped to,can be overrided
107 # $result{pipeto} : Same as action,Command which the $result{data} will be piped to,can be overrided
108 # $result{hook} : Hook action,function process_data will be called
109 # $result{no_subdir} : Do not create sub directories
110 # $result{pass_data} : Data array which will be passed to next level of urlrule
111 # $result{pass_name} : Names of each $result{pass_data}
112 # $result{pass_arg} : Additional arguments to be passed to next level of urlrule
113 # urlrule_quick_parse($url,$rule,$data_exp,$data_map,$pass_exp,$pass_map,$charset)
114 # urlrule_parse_data($url,$rule,$data_exp,$data_map,$charset)
115 # urlrule_parse_pass_data($url,$rule,$pass_exp,$pass_map,$charset)
117 # $result{same_level} : Keep same rule level for passing down
118 # $result{level} : Specify rule level for passing down
119 #================================================================
121 # vim:filetype=perl
122 USAGE
125 close VIMED;
127 if(-f "$source" and ! -x "$source") {
128 chmod 0775,$source;
130 exit 0;