-# WWW::SourceForge.JP\r
-# by hylom\r
-# This code is under GPL.\r
-#\r
-\r
-use LWP;\r
-use HTTP::Cookies;\r
-use HTTP::Request::Common;\r
-use otp::attach;\r
-\r
-package Otp;\r
-\r
-my $ua_string = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1';\r
-my $login_url = 'http://magazine.sourceforge.jp/login.pl';\r
-my $logout_url = 'http://magazine.sourceforge.jp/my/logout';\r
-my $default_cookies = 'otp_cookies.txt';\r
-\r
-sub new {\r
- my $class = shift @_;\r
- my $self = {\r
- 'useragent' => $ua_string,\r
- 'cookies_file' => $default_cookies,\r
- };\r
- return bless $self, $class;\r
-}\r
-\r
-# getter/setter\r
-sub useragent {\r
- my $self = shift @_;\r
- return $self->{useragent};\r
-}\r
-\r
-sub cookies_file {\r
- my $self = shift @_;\r
- return $self->{cookies_file};\r
-}\r
-\r
-sub lwp_ua {\r
- my $self = shift @_;\r
-\r
- my $ua = LWP::UserAgent->new( 'agent' => $self->useragent, );\r
- my $cookie_jar = HTTP::Cookies->new( file => $self->cookies_file, autosave => 1, ignore_discard => 1, );\r
- $ua->cookie_jar( $cookie_jar );\r
-\r
- return $ua;\r
-}\r
-\r
-sub login {\r
- my $self = shift @_;\r
- my $login_name = shift @_;\r
- my $password = shift @_;\r
-\r
- my $ua = $self->lwp_ua;\r
-\r
- my $form_data = {\r
- 'op' => 'userlogin',\r
- 'unickname' => $login_name,\r
- 'upasswd' => $password,\r
- 'userlogin' => 'ログイン',\r
- };\r
- my $resp = $ua->post( $login_url, $form_data );\r
-}\r
-\r
-sub logout {\r
- my $self = shift @_;\r
-\r
- my $ua = $self->lwp_ua;\r
- $ua->get( $logout_url );\r
-}\r
-\r
-sub Attach {\r
- my $self = shift @_;\r
-\r
- if ( ! defined $self->{_attach} ) {\r
- $self->{_attach} = Otp::Attach->new( $self );\r
- }\r
-\r
- return $self->{_attach};\r
-}\r
-\r
-1;\r
+# WWW::SourceForge.JP
+# by hylom
+# This code is under GPL.
+#
+
+use LWP;
+use HTTP::Cookies;
+use HTTP::Request::Common;
+use otp::attach;
+
+package Otp;
+
+my $ua_string = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1';
+my $login_url = 'http://magazine.sourceforge.jp/login.pl';
+my $logout_url = 'http://magazine.sourceforge.jp/my/logout';
+my $default_cookies = 'otp_cookies.txt';
+
+sub new {
+ my $class = shift @_;
+ my $self = {
+ 'useragent' => $ua_string,
+ 'cookies_file' => $default_cookies,
+ };
+ return bless $self, $class;
+}
+
+# getter/setter
+sub useragent {
+ my $self = shift @_;
+ return $self->{useragent};
+}
+
+sub cookies_file {
+ my $self = shift @_;
+ return $self->{cookies_file};
+}
+
+sub lwp_ua {
+ my $self = shift @_;
+
+ my $ua = LWP::UserAgent->new( 'agent' => $self->useragent, );
+ my $cookie_jar = HTTP::Cookies->new( file => $self->cookies_file, autosave => 1, ignore_discard => 1, );
+ $ua->cookie_jar( $cookie_jar );
+
+ return $ua;
+}
+
+sub login {
+ my $self = shift @_;
+ my $login_name = shift @_;
+ my $password = shift @_;
+
+ my $ua = $self->lwp_ua;
+
+ my $form_data = {
+ 'op' => 'userlogin',
+ 'unickname' => $login_name,
+ 'upasswd' => $password,
+ 'userlogin' => 'ログイン',
+ };
+ my $resp = $ua->post( $login_url, $form_data );
+}
+
+sub logout {
+ my $self = shift @_;
+
+ my $ua = $self->lwp_ua;
+ $ua->get( $logout_url );
+}
+
+sub Attach {
+ my $self = shift @_;
+
+ if ( ! defined $self->{_attach} ) {
+ $self->{_attach} = Otp::Attach->new( $self );
+ }
+
+ return $self->{_attach};
+}
+
+1;
-# WWW::SourceForge.JP\r
-# by hylom\r
-# This code is under GPL.\r
-#\r
-\r
-use LWP;\r
-use HTTP::Cookies;\r
-use HTTP::Request::Common;\r
-use SourceForgeJP::Wiki;\r
-\r
-package WWW::SourceForgeJP;\r
-\r
-my $ua_string = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1';\r
-my $login_url = 'https://sourceforge.jp/account/login.php';\r
-my $logout_url = 'https://sourceforge.jp/account/logout.php';\r
-my $default_cookies = 'cookies.txt';\r
-\r
-sub new {\r
- my $class = shift @_;\r
- my $self = {\r
- 'useragent' => $ua_string,\r
- 'cookies_file' => $default_cookies,\r
- };\r
- return bless $self, $class;\r
-}\r
-\r
-# getter/setter\r
-sub useragent {\r
- my $self = shift @_;\r
- return $self->{useragent};\r
-}\r
-\r
-sub cookies_file {\r
- my $self = shift @_;\r
- return $self->{cookies_file};\r
-}\r
-\r
-sub _get_project_dir {\r
- my $self = shift @_;\r
- my $project = shift @_;\r
-\r
- return 'http://sourceforge.jp/projects/' . $project;\r
-}\r
-\r
-sub lwp_ua {\r
- my $self = shift @_;\r
-\r
- my $ua = LWP::UserAgent->new( 'agent' => $self->useragent, );\r
- my $cookie_jar = HTTP::Cookies->new( file => $self->cookies_file, autosave => 1, ignore_discard => 1, );\r
- $ua->cookie_jar( $cookie_jar );\r
-\r
- return $ua;\r
-}\r
-\r
-sub login {\r
- my $self = shift @_;\r
- my $login_name = shift @_;\r
- my $password = shift @_;\r
-\r
- my $ua = $self->lwp_ua;\r
-\r
- my $form_data = {\r
- 'return_to' => '/',\r
- 'login' => '1',\r
- 'form_loginname' => $login_name,\r
- 'form_pw' => $password,\r
- 'stay_in_ssl' => '1',\r
- };\r
- my $resp = $ua->post( $login_url, $form_data );\r
-\r
- if ( $resp->is_error ) {\r
- print $resp->as_string;\r
- return 0;\r
- } else {\r
- return 1;\r
- }\r
-\r
-}\r
-\r
-sub logout {\r
- my $self = shift @_;\r
-\r
- my $ua = $self->lwp_ua;\r
- $ua->get( $logout_url );\r
-}\r
-\r
-sub Wiki {\r
- my $self = shift @_;\r
-\r
- if ( ! defined $self->{_wiki} ) {\r
- $self->{_wiki} = WWW::SourceForgeJP::Wiki->new( $self );\r
- }\r
-\r
- return $self->{_wiki};\r
-}\r
-\r
-1;\r
-\r
+# WWW::SourceForge.JP
+# by hylom
+# This code is under GPL.
+#
+
+use LWP;
+use HTTP::Cookies;
+use HTTP::Request::Common;
+use SourceForgeJP::Wiki;
+
+package WWW::SourceForgeJP;
+
+my $ua_string = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1';
+my $login_url = 'https://sourceforge.jp/account/login.php';
+my $logout_url = 'https://sourceforge.jp/account/logout.php';
+my $default_cookies = 'cookies.txt';
+
+sub new {
+ my $class = shift @_;
+ my $self = {
+ 'useragent' => $ua_string,
+ 'cookies_file' => $default_cookies,
+ };
+ return bless $self, $class;
+}
+
+# getter/setter
+sub useragent {
+ my $self = shift @_;
+ return $self->{useragent};
+}
+
+sub cookies_file {
+ my $self = shift @_;
+ return $self->{cookies_file};
+}
+
+sub _get_project_dir {
+ my $self = shift @_;
+ my $project = shift @_;
+
+ return 'http://sourceforge.jp/projects/' . $project;
+}
+
+sub lwp_ua {
+ my $self = shift @_;
+
+ my $ua = LWP::UserAgent->new( 'agent' => $self->useragent, );
+ my $cookie_jar = HTTP::Cookies->new( file => $self->cookies_file, autosave => 1, ignore_discard => 1, );
+ $ua->cookie_jar( $cookie_jar );
+
+ return $ua;
+}
+
+sub login {
+ my $self = shift @_;
+ my $login_name = shift @_;
+ my $password = shift @_;
+
+ my $ua = $self->lwp_ua;
+
+ my $form_data = {
+ 'return_to' => '/',
+ 'login' => '1',
+ 'form_loginname' => $login_name,
+ 'form_pw' => $password,
+ 'stay_in_ssl' => '1',
+ };
+ my $resp = $ua->post( $login_url, $form_data );
+
+ if ( $resp->is_error ) {
+ print $resp->as_string;
+ return 0;
+ } else {
+ return 1;
+ }
+
+}
+
+sub logout {
+ my $self = shift @_;
+
+ my $ua = $self->lwp_ua;
+ $ua->get( $logout_url );
+}
+
+sub Wiki {
+ my $self = shift @_;
+
+ if ( ! defined $self->{_wiki} ) {
+ $self->{_wiki} = WWW::SourceForgeJP::Wiki->new( $self );
+ }
+
+ return $self->{_wiki};
+}
+
+1;
+
-# WWW::SourceForge.JP::Wiki::Html2Wiki\r
-# by hylom\r
-# This code is under GPL.\r
-#\r
-\r
-use lib 'C:\Users\hirom\Documents\Dev\sfwiki';\r
-package WWW::SourceForgeJP::Wiki::Html2Wiki;\r
-\r
-use warnings;\r
-use strict;\r
-\r
-use utf8;\r
-use open IN => ':utf8';\r
-#use open OUT => ':encoding(Shift_JIS)';\r
-use open OUT => ':utf8';\r
-use open ':std';\r
-\r
-use IO::File;\r
-use HTML::Entities;\r
-\r
-\r
-use Carp;\r
-\r
-### 画像は[[Embed(ほげほげ:hoge.png)]]とかで埋める\r
-\r
-######## 各種設定 #############\r
-my $hyperlink_prefix = "";\r
-my $usage = "usage: faq_gen.pl <source.html>.";\r
-#my $src_file = shift @ARGV or die $usage;\r
-\r
-sub new {\r
- my $class = shift @_;\r
- my $image_prefix = shift @_;\r
- croak "image_prefix is not defined\n" unless( $image_prefix );\r
-\r
- my $self = {\r
- 'image_prefix' => $image_prefix,\r
- };\r
-\r
- return bless $self, $class;\r
-}\r
- \r
-\r
-# convert( HTML-string )\r
-sub convert {\r
- my $self = shift @_;\r
- my $html = shift @_;\r
-\r
- my $div_count = 1;\r
- my $end_flag = 0;\r
- my $anchor_name = "";\r
- my $work_hash = { tmp => '',};\r
-\r
- my $work = "";\r
-\r
- my $work_pre = "";\r
- my $work_post = "";\r
- my $work_pre_ref = \$work;\r
- my $work_post_ref = \$work;\r
-\r
- my $trim_crlf = 1;\r
-\r
- while ( $html =~ s/^([^<]*)<\s*(\/{0,1}[A-Za-z0-9!-]+\s*[^>]*)\s*>//m ) {\r
- my $text = HTML::Entities::decode_entities($1);\r
- if( $trim_crlf == 1 ) {\r
- $text =~ s/\n//mg;\r
- $text =~ s/\s{2,}/ /mg;\r
- }\r
- my $tag_all = $2;\r
-\r
-# print STDERR $tag_all, "\n";\r
- # "で挟まれたテキストは「」で挟む\r
- #$text =~ s/"(.*?)"/「$1」/g;\r
- $work .= $text;\r
-\r
- #タグのparse\r
- $tag_all =~ s/(\S+)\s*>{0,1}//;\r
- my $tag = lc $1;\r
-\r
- my %attr;\r
- my $string = $tag_all;\r
- while( $tag_all ne "" ) {\r
- unless( $tag_all =~ s/^([^=]+)=// ) {\r
- last;\r
- }\r
- my $key = lc $1;\r
- my $val = "";\r
- if ( $tag_all =~ s/^"([^"]*?)"\s*// ) {\r
- $val = $1;\r
- } elsif ( $tag_all =~ s/^'([^']*?)'\s*// ) {\r
- $val = $1;\r
- } elsif ( $tag_all =~ s/^(\S+)\s*// ) {\r
- $val = $1;\r
- } else { \r
- $val = $tag_all;\r
- $tag_all = "";\r
- }\r
- $attr{$key} = $val;\r
- }\r
- # 以上で$tagにtag、%attrにattributeと値の組み合わせが入る\r
- # degug:\r
-# print STDERR "$tag - ";\r
-# for my $key (keys %attr) {\r
-# print STDERR "$key:$attr{$key}, ";\r
-# }\r
-# print STDERR "\n\n";\r
- # end debug\r
-\r
-# #タグの正規化(すべて小文字に)\r
-# # warnings: ""の中に'とかは無視!\r
-# my @terms = split /["']/, $tag;\r
-# my $tag_lc = "";\r
-# while (@terms) {\r
-# my $term = shift @terms;\r
-# $tag_lc .= lc $term;\r
-# if ( $term = shift @terms ) {\r
-# $tag_lc .= qq("$term");\r
-# }\r
-# }\r
-# $tag = $tag_lc;\r
-# $tag =~ s/^(\/{0,1}[a-z0-9!-]+)\s*//;\r
-# my $attr = $tag;\r
-# $tag = $1;\r
-\r
-\r
- # 無視するタグ\r
- my @tag_bypass = qw( meta head /head body /body html /html !doctype script /script tbody /tbody col );\r
- if ( grep /^$tag$/, @tag_bypass ) {\r
- $tag = "";\r
- }\r
-\r
- # <title></title>タグ\r
- if( $tag eq "title" ) {\r
- $work .= "{{{ comment\nh2w-title:";\r
- $tag = "";\r
- }\r
- if( $tag eq "/title" ) {\r
- $work .= "\n}}}\n";\r
- $tag = "";\r
- }\r
- # <rawhtml></rawhtml>タグ(h2w専用タグ)\r
- if( $tag eq "rawhtml" ) {\r
- $html =~ s/^(.*?)<\/rawhtml>//m;\r
- my $raw_html = $1;\r
- $work .= "{{{ html\n";\r
- $work .= $raw_html;\r
- $work .= "\n}}}\n";\r
- $tag = "";\r
- }\r
-\r
- # <footnote></footnote>タグ(h2w専用タグ)\r
- if( $tag eq "footnote" ) {\r
- $html =~ s/^(.*?)<\/footnote>//m;\r
- my $raw_text = $1;\r
- $work .= "[[Footnote($raw_text)]]";\r
- $tag = "";\r
- }\r
-\r
- #<div>をカウント\r
- if ( $tag eq "div" ) {\r
- $div_count++;\r
- $tag = "";\r
- } elsif ( $tag eq "/div" ) {\r
- $div_count--;\r
-# if ( $div_count < 1 ) {\r
-# last;\r
-# }\r
- $tag = "";\r
- }\r
-\r
-\r
- #<!-- -->タグの処理\r
- if ( $tag =~ m/^!--/ ) {\r
- $tag =~ s/^!--//;\r
- $string =~ s/--$//;\r
- \r
- $work .= "\n\n{{{ comment\n";\r
- $work .= "$tag $string";\r
- $work .= "\n}}}\n\n";\r
- $tag = "";\r
- }\r
-\r
- #<br>タグの処理\r
- if ( $tag eq "br" ) {\r
- $work .= "[[BR]]";\r
- $tag = "";\r
- }\r
-\r
- # <p>タグの処理 - 改行2個に\r
- if ( $tag eq "p" ) {\r
- $work .= "\n\n";\r
- $tag = "";\r
- } elsif ( $tag eq "/p" ) {\r
- $work .= "\n\n";\r
- $tag = "";\r
- }\r
-\r
- # <pre>タグの処理\r
- if( $tag eq "pre" ) {\r
- $work .= "\n{{{\n";\r
- $trim_crlf = 0;\r
- $tag = "";\r
- } elsif( $tag eq "/pre" ) {\r
- $work .= "\n}}}\n";\r
- $trim_crlf = 1;\r
- $tag = "";\r
- }\r
-\r
- # <font>タグの処理 - 無視する\r
- if ( $tag eq "font" ) {\r
- $tag = "";\r
- } elsif ( $tag eq "/font" ) {\r
- $tag = "";\r
- }\r
-\r
- # <i>タグの処理\r
- if ( $tag eq "i" ) {\r
- $$work_pre_ref .= q('');\r
- $tag = "";\r
- } elsif ( $tag eq "/i" ) {\r
- $$work_post_ref .= q('');\r
- $tag = "";\r
- }\r
-\r
- # <tt>タグの処理\r
- if ( $tag eq "tt" ) {\r
- $$work_pre_ref .= q(`);\r
- $tag = "";\r
- } elsif ( $tag eq "/tt" ) {\r
- $$work_post_ref .= q(`);\r
- $tag = "";\r
- }\r
-\r
- # <address>タグの処理\r
- if ( $tag eq "address" ) {\r
- $$work_pre_ref .= q('');\r
- $tag = "";\r
- } elsif ( $tag eq "/address" ) {\r
- $$work_post_ref .= q('');\r
- $tag = "";\r
- }\r
-\r
- # <em>タグの処理\r
- if ( $tag eq "em" ) {\r
- $$work_pre_ref .= q('');\r
- $tag = "";\r
- } elsif ( $tag eq "/em" ) {\r
- $$work_post_ref .= q('');\r
- $tag = "";\r
- }\r
-\r
- # <b>タグの処理\r
- if ( $tag eq "b" ) {\r
- $$work_pre_ref .= q(''');\r
- $tag = "";\r
- } elsif ( $tag eq "/b" ) {\r
- $$work_post_ref .= q(''');\r
- $tag = "";\r
- }\r
-\r
- # <strong>タグの処理\r
- if ( $tag eq "strong" ) {\r
- $$work_pre_ref .= q(''');\r
- $tag = "";\r
- } elsif ( $tag eq "/strong" ) {\r
- $$work_post_ref .= q(''');\r
- $tag = "";\r
- }\r
-\r
- # <big>タグの処理\r
- if ( $tag eq "big" ) {\r
- $$work_pre_ref .= q(''');\r
- $tag = "";\r
- } elsif ( $tag eq "/big" ) {\r
- $$work_post_ref .= q(''');\r
- $tag = "";\r
- }\r
-\r
- # <small>タグの処理\r
- if ( $tag eq "small" ) {\r
- $$work_pre_ref .= '__';\r
- $tag = "";\r
- } elsif ( $tag eq "/small" ) {\r
- $$work_post_ref .= '__';\r
- $tag = "";\r
- }\r
-\r
- # <td>タグの処理\r
- if ( $tag eq "td" ) {\r
- $work .= '||';\r
- $tag = "";\r
- } elsif ( $tag eq "/td" ) {\r
- $tag = "";\r
- }\r
-\r
- # <tr>タグの処理\r
- if ( $tag eq "tr" ) {\r
-# $work .= "\n";\r
- $tag = "";\r
- } elsif ( $tag eq "/tr" ) {\r
- $work .= "||\n";\r
- $tag = "";\r
- }\r
-\r
- # <ul>タグの処理\r
- if ( $tag eq "ul" ) {\r
- if ( $work_hash->{ul_level} ) {\r
- $work_hash->{ul_level} = q( ) . $work_hash->{ul_level};\r
- $work_hash->{ul_level} =~ s/1./*/;\r
- } else {\r
- $work_hash->{ul_level} = " * ";\r
- }\r
-# $work .= "\n";\r
- $tag = "";\r
- } elsif ( $tag eq "/ul" ) {\r
- $work_hash->{ul_level} =~ s/^ //;\r
-# $work .= "\n";\r
- $tag = "";\r
- }\r
-\r
- # <ol>タグの処理\r
- if ( $tag eq "ol" ) {\r
- if ( $work_hash->{ul_level} ) {\r
- $work_hash->{ul_level} = q( ) . $work_hash->{ul_level};\r
- $work_hash->{ul_level} =~ s/\*/1./;\r
- } else {\r
- $work_hash->{ul_level} = " 1. ";\r
- }\r
- $work .= "\n";\r
- $tag = "";\r
- } elsif ( $tag eq "/ol" ) {\r
- $work_hash->{ul_level} =~ s/^ //;\r
- $work .= "\n";\r
- $tag = "";\r
- }\r
-\r
- # <li>タグの処理\r
- if ( $tag eq "li" ) {\r
- $work .= "\n";\r
- $work .= $work_hash->{ul_level};\r
- $tag = "";\r
- } elsif ( $tag eq "/li" ) {\r
- $tag = "";\r
- }\r
-\r
-\r
-\r
-\r
- # <table>タグの処理\r
- if ( $tag eq "table" ) {\r
- $work .= "\n\n";\r
- $tag = "";\r
- } elsif ( $tag eq "/table" ) {\r
- $tag = "";\r
- }\r
-\r
-\r
- # <hr>タグの処理\r
- if ( $tag eq "hr" ) {\r
- $work .= "\n\n----\n\n";\r
- $tag = "";\r
- }\r
-\r
- # <a>タグの処理\r
- if ( $tag eq "a" ) {\r
- if ( exists $attr{'name'} ) {\r
- # <a name>タグの処理\r
- $anchor_name = " #$attr{'name'}";\r
- $tag = "";\r
- }\r
- if ( exists $attr{'href'} ) {\r
- # <a href="">タグの処理\r
- my $link_to = $attr{'href'};\r
- if ( ! ($link_to =~ m/^(http:\/\/|mailto:)/ ) ) {\r
- $link_to =~ s/\.s{0,1}html//;\r
- $link_to = $hyperlink_prefix . $link_to;\r
- }\r
- $work_hash->{href} = $link_to;\r
- $work_hash->{href_stack} = $work;\r
- $work_hash->{href_stack_post} = "";\r
- $work = "";\r
- $tag = "";\r
- $work_pre = "";\r
- $work_post = "";\r
- $work_pre_ref = \$work_pre;\r
- $work_post_ref = \$work_post;\r
- }\r
- }\r
- if ( $tag eq "/a" ) {\r
- if ( $work_pre_ref != \$work_pre ) {\r
- #<a name>タグを閉じる\r
- $tag = "";\r
- } else {\r
- $work =~ s/\[/[/g; # 半角[]はリンクブラケットとして扱われるので変換\r
- $work =~ s/\]/]/g;\r
- $work = $work_hash->{href_stack} . $work_pre . \r
- "[$work_hash->{href} $work]" . $work_hash->{href_stack_post} . \r
- $work_post;\r
- $work_hash->{href} = "";\r
- $work_hash->{href_stack} = "";\r
- $work_hash->{href_stack_post} = "";\r
- $work_pre_ref = \$work;\r
- $work_post_ref = \$work;\r
- $tag = "";\r
- }\r
- }\r
-\r
-\r
- # <h[0-9]>タグの処理\r
- if ( $tag =~ m/^h([0-9])$/ ) {\r
- my $h_level = $1;\r
- $work .= "\n\n";\r
- for ( my $i = 0; $i < $h_level; $i++ ) {\r
- $work .= "=";\r
- }\r
- $work .= q( );\r
- $tag = "";\r
- } elsif ( $tag =~ m/^\/h([0-9])$/ ) {\r
- my $h_level = $1;\r
- $work .= q( );\r
- for ( my $i = 0; $i < $h_level; $i++ ) {\r
- $work .= "=";\r
- }\r
- $work .= "$anchor_name\n\n";\r
- $anchor_name = "";\r
- $tag = "";\r
- }\r
-\r
- # <img>タグの処理\r
- if ( $tag =~ m/^img$/ ) {\r
- my $img_location = $self->get_img_location( $attr{src} );\r
- my $opt = "";\r
-\r
- if ( exists $attr{'align'} ) {\r
- if ( $attr{'align'} eq 'left' ) {\r
- $opt = " float=left";\r
- } elsif( $attr{'align'} eq 'right' ) {\r
- $opt = " float=right";\r
- }\r
- $work .= "[[Embed($img_location$opt)]]\n";\r
- }\r
- $tag = "";\r
- }\r
-\r
-# $work .= "<$tag>" if( $tag ne "" );\r
- print STDERR "$tag: unimplemented!\n" if( $tag ne "" );\r
- }\r
-\r
- $work =~ s/^\n*//m;\r
- $work =~ s/\n{3,}/\n\n/mg;\r
-\r
- $work =~ s/\\n/\n/g;\r
- $work =~ s/\\\\/\\/g;\r
-\r
- print $work;\r
-}\r
-\r
-sub get_img_location {\r
- my $self = shift @_;\r
- my $src = shift @_;\r
-\r
- return "$self->{image_prefix}$src";\r
-}\r
-\r
+# WWW::SourceForge.JP::Wiki::Html2Wiki
+# by hylom
+# This code is under GPL.
+#
+
+use lib 'C:\Users\hirom\Documents\Dev\sfwiki';
+package WWW::SourceForgeJP::Wiki::Html2Wiki;
+
+use warnings;
+use strict;
+
+use utf8;
+use open IN => ':utf8';
+#use open OUT => ':encoding(Shift_JIS)';
+use open OUT => ':utf8';
+use open ':std';
+
+use IO::File;
+use HTML::Entities;
+
+
+use Carp;
+
+### 画像は[[Embed(ほげほげ:hoge.png)]]とかで埋める
+
+######## 各種設定 #############
+my $hyperlink_prefix = "";
+my $usage = "usage: faq_gen.pl <source.html>.";
+#my $src_file = shift @ARGV or die $usage;
+
+sub new {
+ my $class = shift @_;
+ my $image_prefix = shift @_;
+ croak "image_prefix is not defined\n" unless( $image_prefix );
+
+ my $self = {
+ 'image_prefix' => $image_prefix,
+ };
+
+ return bless $self, $class;
+}
+
+
+# convert( HTML-string )
+sub convert {
+ my $self = shift @_;
+ my $html = shift @_;
+
+ my $div_count = 1;
+ my $end_flag = 0;
+ my $anchor_name = "";
+ my $work_hash = { tmp => '',};
+
+ my $work = "";
+
+ my $work_pre = "";
+ my $work_post = "";
+ my $work_pre_ref = \$work;
+ my $work_post_ref = \$work;
+
+ my $trim_crlf = 1;
+
+ while ( $html =~ s/^([^<]*)<\s*(\/{0,1}[A-Za-z0-9!-]+\s*[^>]*)\s*>//m ) {
+ my $text = HTML::Entities::decode_entities($1);
+ if( $trim_crlf == 1 ) {
+ $text =~ s/\n//mg;
+ $text =~ s/\s{2,}/ /mg;
+ }
+ my $tag_all = $2;
+
+# print STDERR $tag_all, "\n";
+ # "で挟まれたテキストは「」で挟む
+ #$text =~ s/"(.*?)"/「$1」/g;
+ $work .= $text;
+
+ #タグのparse
+ $tag_all =~ s/(\S+)\s*>{0,1}//;
+ my $tag = lc $1;
+
+ my %attr;
+ my $string = $tag_all;
+ while( $tag_all ne "" ) {
+ unless( $tag_all =~ s/^([^=]+)=// ) {
+ last;
+ }
+ my $key = lc $1;
+ my $val = "";
+ if ( $tag_all =~ s/^"([^"]*?)"\s*// ) {
+ $val = $1;
+ } elsif ( $tag_all =~ s/^'([^']*?)'\s*// ) {
+ $val = $1;
+ } elsif ( $tag_all =~ s/^(\S+)\s*// ) {
+ $val = $1;
+ } else {
+ $val = $tag_all;
+ $tag_all = "";
+ }
+ $attr{$key} = $val;
+ }
+ # 以上で$tagにtag、%attrにattributeと値の組み合わせが入る
+ # degug:
+# print STDERR "$tag - ";
+# for my $key (keys %attr) {
+# print STDERR "$key:$attr{$key}, ";
+# }
+# print STDERR "\n\n";
+ # end debug
+
+# #タグの正規化(すべて小文字に)
+# # warnings: ""の中に'とかは無視!
+# my @terms = split /["']/, $tag;
+# my $tag_lc = "";
+# while (@terms) {
+# my $term = shift @terms;
+# $tag_lc .= lc $term;
+# if ( $term = shift @terms ) {
+# $tag_lc .= qq("$term");
+# }
+# }
+# $tag = $tag_lc;
+# $tag =~ s/^(\/{0,1}[a-z0-9!-]+)\s*//;
+# my $attr = $tag;
+# $tag = $1;
+
+
+ # 無視するタグ
+ my @tag_bypass = qw( meta head /head body /body html /html !doctype script /script tbody /tbody col );
+ if ( grep /^$tag$/, @tag_bypass ) {
+ $tag = "";
+ }
+
+ # <title></title>タグ
+ if( $tag eq "title" ) {
+ $work .= "{{{ comment\nh2w-title:";
+ $tag = "";
+ }
+ if( $tag eq "/title" ) {
+ $work .= "\n}}}\n";
+ $tag = "";
+ }
+ # <rawhtml></rawhtml>タグ(h2w専用タグ)
+ if( $tag eq "rawhtml" ) {
+ $html =~ s/^(.*?)<\/rawhtml>//m;
+ my $raw_html = $1;
+ $work .= "{{{ html\n";
+ $work .= $raw_html;
+ $work .= "\n}}}\n";
+ $tag = "";
+ }
+
+ # <footnote></footnote>タグ(h2w専用タグ)
+ if( $tag eq "footnote" ) {
+ $html =~ s/^(.*?)<\/footnote>//m;
+ my $raw_text = $1;
+ $work .= "[[Footnote($raw_text)]]";
+ $tag = "";
+ }
+
+ #<div>をカウント
+ if ( $tag eq "div" ) {
+ $div_count++;
+ $tag = "";
+ } elsif ( $tag eq "/div" ) {
+ $div_count--;
+# if ( $div_count < 1 ) {
+# last;
+# }
+ $tag = "";
+ }
+
+
+ #<!-- -->タグの処理
+ if ( $tag =~ m/^!--/ ) {
+ $tag =~ s/^!--//;
+ $string =~ s/--$//;
+
+ $work .= "\n\n{{{ comment\n";
+ $work .= "$tag $string";
+ $work .= "\n}}}\n\n";
+ $tag = "";
+ }
+
+ #<br>タグの処理
+ if ( $tag eq "br" ) {
+ $work .= "[[BR]]";
+ $tag = "";
+ }
+
+ # <p>タグの処理 - 改行2個に
+ if ( $tag eq "p" ) {
+ $work .= "\n\n";
+ $tag = "";
+ } elsif ( $tag eq "/p" ) {
+ $work .= "\n\n";
+ $tag = "";
+ }
+
+ # <pre>タグの処理
+ if( $tag eq "pre" ) {
+ $work .= "\n{{{\n";
+ $trim_crlf = 0;
+ $tag = "";
+ } elsif( $tag eq "/pre" ) {
+ $work .= "\n}}}\n";
+ $trim_crlf = 1;
+ $tag = "";
+ }
+
+ # <font>タグの処理 - 無視する
+ if ( $tag eq "font" ) {
+ $tag = "";
+ } elsif ( $tag eq "/font" ) {
+ $tag = "";
+ }
+
+ # <i>タグの処理
+ if ( $tag eq "i" ) {
+ $$work_pre_ref .= q('');
+ $tag = "";
+ } elsif ( $tag eq "/i" ) {
+ $$work_post_ref .= q('');
+ $tag = "";
+ }
+
+ # <tt>タグの処理
+ if ( $tag eq "tt" ) {
+ $$work_pre_ref .= q(`);
+ $tag = "";
+ } elsif ( $tag eq "/tt" ) {
+ $$work_post_ref .= q(`);
+ $tag = "";
+ }
+
+ # <address>タグの処理
+ if ( $tag eq "address" ) {
+ $$work_pre_ref .= q('');
+ $tag = "";
+ } elsif ( $tag eq "/address" ) {
+ $$work_post_ref .= q('');
+ $tag = "";
+ }
+
+ # <em>タグの処理
+ if ( $tag eq "em" ) {
+ $$work_pre_ref .= q('');
+ $tag = "";
+ } elsif ( $tag eq "/em" ) {
+ $$work_post_ref .= q('');
+ $tag = "";
+ }
+
+ # <b>タグの処理
+ if ( $tag eq "b" ) {
+ $$work_pre_ref .= q(''');
+ $tag = "";
+ } elsif ( $tag eq "/b" ) {
+ $$work_post_ref .= q(''');
+ $tag = "";
+ }
+
+ # <strong>タグの処理
+ if ( $tag eq "strong" ) {
+ $$work_pre_ref .= q(''');
+ $tag = "";
+ } elsif ( $tag eq "/strong" ) {
+ $$work_post_ref .= q(''');
+ $tag = "";
+ }
+
+ # <big>タグの処理
+ if ( $tag eq "big" ) {
+ $$work_pre_ref .= q(''');
+ $tag = "";
+ } elsif ( $tag eq "/big" ) {
+ $$work_post_ref .= q(''');
+ $tag = "";
+ }
+
+ # <small>タグの処理
+ if ( $tag eq "small" ) {
+ $$work_pre_ref .= '__';
+ $tag = "";
+ } elsif ( $tag eq "/small" ) {
+ $$work_post_ref .= '__';
+ $tag = "";
+ }
+
+ # <td>タグの処理
+ if ( $tag eq "td" ) {
+ $work .= '||';
+ $tag = "";
+ } elsif ( $tag eq "/td" ) {
+ $tag = "";
+ }
+
+ # <tr>タグの処理
+ if ( $tag eq "tr" ) {
+# $work .= "\n";
+ $tag = "";
+ } elsif ( $tag eq "/tr" ) {
+ $work .= "||\n";
+ $tag = "";
+ }
+
+ # <ul>タグの処理
+ if ( $tag eq "ul" ) {
+ if ( $work_hash->{ul_level} ) {
+ $work_hash->{ul_level} = q( ) . $work_hash->{ul_level};
+ $work_hash->{ul_level} =~ s/1./*/;
+ } else {
+ $work_hash->{ul_level} = " * ";
+ }
+# $work .= "\n";
+ $tag = "";
+ } elsif ( $tag eq "/ul" ) {
+ $work_hash->{ul_level} =~ s/^ //;
+# $work .= "\n";
+ $tag = "";
+ }
+
+ # <ol>タグの処理
+ if ( $tag eq "ol" ) {
+ if ( $work_hash->{ul_level} ) {
+ $work_hash->{ul_level} = q( ) . $work_hash->{ul_level};
+ $work_hash->{ul_level} =~ s/\*/1./;
+ } else {
+ $work_hash->{ul_level} = " 1. ";
+ }
+ $work .= "\n";
+ $tag = "";
+ } elsif ( $tag eq "/ol" ) {
+ $work_hash->{ul_level} =~ s/^ //;
+ $work .= "\n";
+ $tag = "";
+ }
+
+ # <li>タグの処理
+ if ( $tag eq "li" ) {
+ $work .= "\n";
+ $work .= $work_hash->{ul_level};
+ $tag = "";
+ } elsif ( $tag eq "/li" ) {
+ $tag = "";
+ }
+
+
+
+
+ # <table>タグの処理
+ if ( $tag eq "table" ) {
+ $work .= "\n\n";
+ $tag = "";
+ } elsif ( $tag eq "/table" ) {
+ $tag = "";
+ }
+
+
+ # <hr>タグの処理
+ if ( $tag eq "hr" ) {
+ $work .= "\n\n----\n\n";
+ $tag = "";
+ }
+
+ # <a>タグの処理
+ if ( $tag eq "a" ) {
+ if ( exists $attr{'name'} ) {
+ # <a name>タグの処理
+ $anchor_name = " #$attr{'name'}";
+ $tag = "";
+ }
+ if ( exists $attr{'href'} ) {
+ # <a href="">タグの処理
+ my $link_to = $attr{'href'};
+ if ( ! ($link_to =~ m/^(http:\/\/|mailto:)/ ) ) {
+ $link_to =~ s/\.s{0,1}html//;
+ $link_to = $hyperlink_prefix . $link_to;
+ }
+ $work_hash->{href} = $link_to;
+ $work_hash->{href_stack} = $work;
+ $work_hash->{href_stack_post} = "";
+ $work = "";
+ $tag = "";
+ $work_pre = "";
+ $work_post = "";
+ $work_pre_ref = \$work_pre;
+ $work_post_ref = \$work_post;
+ }
+ }
+ if ( $tag eq "/a" ) {
+ if ( $work_pre_ref != \$work_pre ) {
+ #<a name>タグを閉じる
+ $tag = "";
+ } else {
+ $work =~ s/\[/[/g; # 半角[]はリンクブラケットとして扱われるので変換
+ $work =~ s/\]/]/g;
+ $work = $work_hash->{href_stack} . $work_pre .
+ "[$work_hash->{href} $work]" . $work_hash->{href_stack_post} .
+ $work_post;
+ $work_hash->{href} = "";
+ $work_hash->{href_stack} = "";
+ $work_hash->{href_stack_post} = "";
+ $work_pre_ref = \$work;
+ $work_post_ref = \$work;
+ $tag = "";
+ }
+ }
+
+
+ # <h[0-9]>タグの処理
+ if ( $tag =~ m/^h([0-9])$/ ) {
+ my $h_level = $1;
+ $work .= "\n\n";
+ for ( my $i = 0; $i < $h_level; $i++ ) {
+ $work .= "=";
+ }
+ $work .= q( );
+ $tag = "";
+ } elsif ( $tag =~ m/^\/h([0-9])$/ ) {
+ my $h_level = $1;
+ $work .= q( );
+ for ( my $i = 0; $i < $h_level; $i++ ) {
+ $work .= "=";
+ }
+ $work .= "$anchor_name\n\n";
+ $anchor_name = "";
+ $tag = "";
+ }
+
+ # <img>タグの処理
+ if ( $tag =~ m/^img$/ ) {
+ my $img_location = $self->get_img_location( $attr{src} );
+ my $opt = "";
+
+ if ( exists $attr{'align'} ) {
+ if ( $attr{'align'} eq 'left' ) {
+ $opt = " float=left";
+ } elsif( $attr{'align'} eq 'right' ) {
+ $opt = " float=right";
+ }
+ $work .= "[[Embed($img_location$opt)]]\n";
+ }
+ $tag = "";
+ }
+
+# $work .= "<$tag>" if( $tag ne "" );
+ print STDERR "$tag: unimplemented!\n" if( $tag ne "" );
+ }
+
+ $work =~ s/^\n*//m;
+ $work =~ s/\n{3,}/\n\n/mg;
+
+ $work =~ s/\\n/\n/g;
+ $work =~ s/\\\\/\\/g;
+
+ print $work;
+}
+
+sub get_img_location {
+ my $self = shift @_;
+ my $src = shift @_;
+
+ return "$self->{image_prefix}$src";
+}
+
--- /dev/null
+# deterfile.py
+"""deterfile.py - determine file type"""
+
+import os
+import os.path
+import re
+
+_file_cmd = "file %s"
+
+def file(path):
+ """
+ determine given file's type.
+ This function returns strings.
+
+ @param path: filepath you want to determine
+ @type path: string
+ """
+
+ if not os.path.isfile(path):
+ return ("file not exist.",)
+
+ cmd = _file_cmd % path
+ escaped_path = path.replace("\\", "\\\\");
+ stdout = os.popen(cmd, "r")
+ results = []
+ for line in stdout:
+ if re.search(r"^%s:" % escaped_path, line):
+ line = re.sub(r"^%s:\s*" % escaped_path, "", line)
+ tpl = line.strip().split(",")
+ results.extend([x.strip() for x in tpl])
+ stdout.close()
+ return results
+
+#### test code
+# import sys
+
+# tgt = sys.argv[1]
+# r = file(tgt)
+# for item in r:
+# print item
-#!/usr/bin/perl\r
-\r
-use warnings;\r
-use strict;\r
-\r
-use lib 'C:\Users\hirom\Documents\Dev\sfwiki';\r
-\r
-use utf8;\r
-use open IO => ':utf8';\r
-use open ':std';\r
-\r
-use SourceForgeJP::Wiki::Html2Wiki;\r
-\r
-my $image_basedir = shift @ARGV;\r
-\r
-my $html = do {local $/; <> };\r
-\r
-my $converter = WWW::SourceForgeJP::Wiki::Html2Wiki->new($image_basedir);\r
-my $wiki = $converter->convert($html);\r
-\r
-print $wiki;\r
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use lib 'C:\Users\hirom\Documents\Dev\sfwiki';
+
+use utf8;
+use open IO => ':utf8';
+use open ':std';
+
+use SourceForgeJP::Wiki::Html2Wiki;
+
+my $image_basedir = shift @ARGV;
+
+my $html = do {local $/; <> };
+
+my $converter = WWW::SourceForgeJP::Wiki::Html2Wiki->new($image_basedir);
+my $wiki = $converter->convert($html);
+
+print $wiki;
import pickle
import HTMLTagFilter
+import deterfile
#sys.stdin = codecs.getreader('utf_8')(sys.stdin)
#sys.stdout = codecs.getwriter('utf_8')(sys.stdout)
elif re.search(ur"^☆\*", line):
self._anchor = re.sub(ur"^☆\*", "", line).strip()
continue
+ elif re.search(ur"^☆clear\s+", line):
+ self._clear(line)
+ continue
elif re.search(ur"^・", line):
self._ulist(line)
continue
# end-of-loop
+ def _clear(self, line):
+ print """<div style="clear:left;"> </div>
+"""
+
def _head_l(self, line):
line = line.rstrip()
if re.search(ur"\*{[a-zA-Z0-9_]*}\s*$", line):
print flow_footer
- def _fig_start(self, cap=""):
- return """<table align="center" border="0" cellpadding="0" cellspacing="0">
+ def _fig_start(self, cap="", styles=[], width=0, height=0):
+ params = dict(style="", tablewidth="")
+ if width != 0:
+ params["style"] = "width:%d;" % (width,)
+ params["tablewidth"] = 'width="%d"' % (width,)
+
+ if "lfloat" in styles:
+ return """<table %(tablewidth)s align="center" border="0" cellpadding="0" cellspacing="0" style="float:left; padding-left: 0.5em; %(style)s">
<tr> <td valign="top" align="center">
- """
+ """ % params
+ elif "left" in styles:
+ return """<table %(tablewidth)s border="0" cellpadding="0" cellspacing="0" style="padding-left: 0.5em; %(style)s">
+ <tr> <td valign="top" align="center">
+ """ %params
+ else:
+ return """<table %(tablewidth)s align="center" border="0" cellpadding="0" cellspacing="0">
+ <tr> <td valign="top" align="center">
+ """ % params
- def _fig_end(self, cap=""):
+ def _fig_end(self, cap="", styles=[]):
return """</td> </tr>
<tr> <td><span style="font-size: 80%%; font-weight: bold;">
%s
if self._release == 1:
self._fig_release(line)
else:
- self._fig_org(line)
-
+ self._fig(line)
+
+ def _get_png_geom(self, filepath):
+ desc = deterfile.file(filepath)
+ m = re.match(r"([0-9]+)\s*x\s*([0-9]+)", desc[1])
+ if m:
+ w = m.group(1)
+ h = m.group(2)
+ return (int(w), int(h))
+ else:
+ return None
- def _fig_org(self, line):
+ def _fig(self, line):
try:
str_title = re.search(ur"^☆(図.*)$", line).group(1)
except AttributeError:
str_title = ""
if str_title.find(u"図*") == 0:
str_title = str_title.replace(u"図*", "")
- print self._fig_start()
-
line = self.input_iter.next()
+ styles = []
+ if line.find("@") == 0:
+ styles = line.strip().replace("@", "").split(",")
+ line = self.input_iter.next()
+
imgname = ""
imgname_s = ""
hash = ""
imgname = os.path.join(self._image_dir, imgname)
imgname_s = match_o1.group(2)
+ geom = self._get_png_geom(imgname_s)
+ if geom:
+ w = geom[0]
+ h = geom[1]
+ print self._fig_start("", styles, width=w, height=h)
+ else:
+ print self._fig_start("", styles)
print self._anchored_fig(imgname, str_title, imgname_s)
-
-# if not os.path.isfile(imgname_s):
-# imgname_s = imgname
-
-# print """<a href="%s">
-# <img src="%s" alt="%s">
-# </a>
-# """ % (imgname, imgname_s, str_title)
+ print self._fig_end(str_title, styles);
dic = self.index("figs")
dic.append(imgname)
if imgname_s != "":
dic.append(imgname_s)
- print self._fig_end(str_title);
def _anchored_fig(self, file, alt, file_s=""):
-#!/usr/bin/env python\r
-# -*- coding: utf-8 -*-\r
- \r
-import sys\r
-import os\r
-import os.path\r
-import re\r
-import codecs\r
-import hashlib\r
-import dircache\r
-\r
-sys.stdin = codecs.getreader('utf_8')(sys.stdin)\r
-sys.stdout = codecs.getwriter('utf_8')(sys.stdout)\r
-\r
-\r
-usage = "%s directory1 [directory2 ...]" % sys.argv[0]\r
-\r
-if len(sys.argv) < 2:\r
- sys.exit(usage)\r
-\r
-for index in range(1, len(sys.argv)):\r
- dir = sys.argv[index]\r
- if not os.path.isdir(dir):\r
- print >> sys.stderr, "%s is not a directory. skip.\n" % dir\r
- continue\r
-\r
- for target in dircache.listdir(dir):\r
- tpath = os.path.join(dir, target)\r
- if not os.path.isfile(tpath):\r
- print >> sys.stderr, "%s is not a file. skip.\n" % tpath\r
- continue\r
-\r
- f = open( tpath, "rb")\r
- buf = f.read()\r
- f.close()\r
- m = hashlib.md5()\r
- m.update(buf)\r
- print m.hexdigest() + "\t" + target\r
-\r
-\r
-\r
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys
+import os
+import os.path
+import re
+import codecs
+import hashlib
+import dircache
+
+sys.stdin = codecs.getreader('utf_8')(sys.stdin)
+sys.stdout = codecs.getwriter('utf_8')(sys.stdout)
+
+
+usage = "%s directory1 [directory2 ...]" % sys.argv[0]
+
+if len(sys.argv) < 2:
+ sys.exit(usage)
+
+for index in range(1, len(sys.argv)):
+ dir = sys.argv[index]
+ if not os.path.isdir(dir):
+ print >> sys.stderr, "%s is not a directory. skip.\n" % dir
+ continue
+
+ for target in dircache.listdir(dir):
+ tpath = os.path.join(dir, target)
+ if not os.path.isfile(tpath):
+ print >> sys.stderr, "%s is not a file. skip.\n" % tpath
+ continue
+
+ f = open( tpath, "rb")
+ buf = f.read()
+ f.close()
+ m = hashlib.md5()
+ m.update(buf)
+ print m.hexdigest() + "\t" + target
+
+
+
-#!/usr/bin/perl\r
-# SourceForge.JP Wiki manipulator\r
-# by hylom\r
-# This code is under GPL.\r
-#\r
-\r
-use warnings;\r
-use strict;\r
-\r
-use utf8;\r
-use open IO => ':utf8';\r
-use open ':std';\r
-\r
-# 下記は環境に応じて適当に変更\r
-# Otp.pm およびOtpディレクトリ(Otp/Attach.pm)があるディレクトリを指定する\r
-# use lib '~/bin'\r
-use lib 'C:\Users\hirom\bin\otptools';\r
-\r
-use Otp;\r
-use IO::File;\r
-use Term::Prompt;\r
-use URI::Escape;\r
-use Encode;\r
-use File::Temp;\r
-use Getopt::Std;\r
-\r
-my $usage = <<EOD;\r
-otp_attach.pl file \r
-\r
-example:\r
- otp_attach.pl login -u loginname -p password\r
- otp_attach.pl logout\r
- otp_attach.pl attach -i sid -f attachmentfile\r
-EOD\r
-\r
-my $command = shift @ARGV;\r
-unless( $command ) {\r
- print $usage;\r
- exit;\r
-}\r
-\r
-if ( $command eq 'login' ) { #login\r
- my %opts;\r
- getopt('up', \%opts);\r
- my $login_name;\r
- my $password;\r
-\r
- if ( defined $opts{'u'} ) {\r
- $login_name = $opts{'u'};\r
- } else {\r
- $login_name = prompt( 'x', 'loginname:', '', '' );\r
- }\r
-\r
- if ( defined $opts{'p'} ) {\r
- $password = $opts{'p'};\r
- } else {\r
- $password = prompt( 'p', 'password:', '', '' );\r
- print "\n";\r
- }\r
-\r
- print "do login...\n";\r
- login( $login_name, $password);\r
-\r
-} elsif ( $command eq 'attach' ) { #attach\r
- my %opts;\r
- getopt('if', \%opts);\r
-\r
- my $sid = $opts{'i'};\r
- my $file = $opts{'f'};\r
- add_attachment( $sid, $file );\r
-\r
-} elsif ( $command eq 'logout' ) { #logout\r
- print "do logout...\n";\r
- logout();\r
-\r
-} else { #other\r
- print $usage;\r
- exit;\r
-}\r
-\r
-sub login {\r
- my $login_name = shift @_;\r
- my $password = shift @_;\r
-\r
- my $otp = Otp->new();\r
- $otp->login( $login_name, $password );\r
-}\r
-\r
-sub logout {\r
- my $otp = Otp->new();\r
- $otp->logout();\r
-}\r
-\r
-sub add_attachment {\r
- my $sid = shift @_;\r
- my $file = shift @_;\r
-\r
- if ( ! -e $file ) {\r
- die "$file is not exist.\n";\r
- }\r
-\r
- my $otp = Otp->new();\r
- my $ret = $otp->Attach->post_attachment( sid => $sid,\r
- file => $file );\r
-\r
- if ( $ret ) {\r
- print "$file: upload succeed.\n";\r
- } else {\r
- print "$file: upload failed.\n";\r
- }\r
-}\r
-\r
+#!/usr/bin/perl
+# SourceForge.JP Wiki manipulator
+# by hylom
+# This code is under GPL.
+#
+
+use warnings;
+use strict;
+
+use utf8;
+use open IO => ':utf8';
+use open ':std';
+
+# 下記は環境に応じて適当に変更
+# Otp.pm およびOtpディレクトリ(Otp/Attach.pm)があるディレクトリを指定する
+# use lib '~/bin'
+use lib 'C:\Users\hirom\bin\otptools';
+
+use Otp;
+use IO::File;
+use Term::Prompt;
+use URI::Escape;
+use Encode;
+use File::Temp;
+use Getopt::Std;
+
+my $usage = <<EOD;
+otp_attach.pl file
+
+example:
+ otp_attach.pl login -u loginname -p password
+ otp_attach.pl logout
+ otp_attach.pl attach -i sid -f attachmentfile
+EOD
+
+my $command = shift @ARGV;
+unless( $command ) {
+ print $usage;
+ exit;
+}
+
+if ( $command eq 'login' ) { #login
+ my %opts;
+ getopt('up', \%opts);
+ my $login_name;
+ my $password;
+
+ if ( defined $opts{'u'} ) {
+ $login_name = $opts{'u'};
+ } else {
+ $login_name = prompt( 'x', 'loginname:', '', '' );
+ }
+
+ if ( defined $opts{'p'} ) {
+ $password = $opts{'p'};
+ } else {
+ $password = prompt( 'p', 'password:', '', '' );
+ print "\n";
+ }
+
+ print "do login...\n";
+ login( $login_name, $password);
+
+} elsif ( $command eq 'attach' ) { #attach
+ my %opts;
+ getopt('if', \%opts);
+
+ my $sid = $opts{'i'};
+ my $file = $opts{'f'};
+ add_attachment( $sid, $file );
+
+} elsif ( $command eq 'logout' ) { #logout
+ print "do logout...\n";
+ logout();
+
+} else { #other
+ print $usage;
+ exit;
+}
+
+sub login {
+ my $login_name = shift @_;
+ my $password = shift @_;
+
+ my $otp = Otp->new();
+ $otp->login( $login_name, $password );
+}
+
+sub logout {
+ my $otp = Otp->new();
+ $otp->logout();
+}
+
+sub add_attachment {
+ my $sid = shift @_;
+ my $file = shift @_;
+
+ if ( ! -e $file ) {
+ die "$file is not exist.\n";
+ }
+
+ my $otp = Otp->new();
+ my $ret = $otp->Attach->post_attachment( sid => $sid,
+ file => $file );
+
+ if ( $ret ) {
+ print "$file: upload succeed.\n";
+ } else {
+ print "$file: upload failed.\n";
+ }
+}
+
-#!/usr/bin/env python\r
-# -*- coding: utf-8 -*-\r
-"""\r
-otptools base module - retain session/login info\r
-"""\r
-import sys\r
-import os\r
-import copy\r
-import urllib\r
-import httplib\r
-import re\r
-\r
-from BeautifulSoup import BeautifulSoup\r
-\r
-OTP_LOGIN_URL = "http://magazine.sourceforge.jp/login.pl"\r
-OTP_LOGIN_HOST = "magazine.sourceforge.jp"\r
-OTP_LOGIN_PATH = "/login.pl"\r
-\r
-OTP_LOGIN_PARAM = {\r
- "op":"userlogin",\r
- "unickname":"",\r
- "upasswd":"",\r
-# "login_temp":0,\r
- "userlogin":"ログイン",\r
- }\r
-\r
-OTP_LIST_PATH = "/admin.pl"\r
-\r
-BROWSER = "Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7 (.NET CLR 3.5.30729) "\r
-\r
-\r
-class otptools(object):\r
- """\r
- Open Tech Press management library core module.\r
- """\r
-\r
- def __init__(self, path_cookie, login_name="", login_password=""):\r
- """\r
- @param path_cookie: path of file which cookie's information stored.\r
- @type path_cookie: stinrg\r
-\r
- @param login_name: OTP's login name for use.\r
- @type login_name: string\r
-\r
- @param login_password: OTP's login password.\r
- @type login_password: string\r
- """\r
- self.path_cookie = path_cookie\r
- self.unickname = login_name\r
- self.upasswd = login_password\r
- self.cookie = ""\r
-\r
- def get_cookie(self):\r
- return self.cookie\r
-\r
- def login(self, user="", passwd=""):\r
- login_param = copy.deepcopy(OTP_LOGIN_PARAM)\r
-\r
- if user != "":\r
- self.unickname = user\r
- if passwd != "":\r
- self.upasswd = passwd\r
-\r
- login_param["unickname"] = self.unickname\r
- login_param["upasswd"] = self.upasswd\r
-\r
-# for item in login_param:\r
-# print "%s > %s" % (item, login_param[item] )\r
-\r
- encoded_data = urllib.urlencode(login_param)\r
-# print encoded_data\r
-\r
- headers = {\r
- "User-Agent": BROWSER,\r
- "Content-type": "application/x-www-form-urlencoded",\r
- "Accept": "text/plain",\r
- }\r
-\r
- obj = httplib.HTTPConnection(OTP_LOGIN_HOST)\r
- obj.request("POST", OTP_LOGIN_PATH, encoded_data, headers)\r
- resp = obj.getresponse()\r
- headers = resp.getheaders()\r
-\r
-# for item in headers:\r
-# print item\r
-\r
- for header in headers:\r
- if header[0] == "set-cookie":\r
- str_cookie = header[1]\r
- break\r
- else:\r
- return -1\r
-\r
- self.cookie = str_cookie\r
- return 1\r
-\r
- def save_cookie(self):\r
- file_obj = open(self.path_cookie, "w")\r
- file_obj.write(self.cookie)\r
- file_obj.close()\r
-\r
- def load_cookie(self):\r
- file_obj = open(self.path_cookie, "r")\r
- self.cookie = file_obj.readline()\r
- file_obj.close()\r
-\r
- def get_list(self, skips=0):\r
- """\r
- get otp story list.\r
-\r
- @param skips: index\r
- @type skips: int\r
- """\r
- path = OTP_LIST_PATH\r
- if skips != 0:\r
- path = path + "?section=&op=list&next=%s" % skips\r
-\r
-# sys.stderr.write( path + "\n" )\r
- return self._retrieve_html( path )\r
-\r
- def _retrieve_html(self, path):\r
- """\r
- retrive html from url.\r
- """\r
- headers = {\r
- "User-Agent": BROWSER,\r
- "Content-type": "application/x-www-form-urlencoded",\r
- "Accept": "text/plain",\r
- "Cookie": self.cookie,\r
- }\r
- obj = httplib.HTTPConnection(OTP_LOGIN_HOST)\r
-\r
- try:\r
- obj.request("GET", path, "", headers)\r
- except socket.error:\r
- # 10060:timed out\r
- sys.stderr.write( "socket error: %s" % (path) )\r
- return ""\r
-\r
- resp = obj.getresponse()\r
- headers = dict(resp.getheaders())\r
-\r
- if resp.status == 302: # redirect\r
- return self._retrieve_html( headers["location"] )\r
-\r
- return resp.read()\r
-\r
- def get_tags(self, url):\r
- """\r
- get story's tags (topics).\r
- """\r
- html = self._retrieve_html(url)\r
- if html == "":\r
- return ""\r
-\r
- tags = []\r
- match = re.search( r'<meta name="description" content=".* -- article related to (.*)\..*">', html, re.M )\r
-# 分割されたWebページを1つにつなげる「AutoPager」拡張 -- article related to 森川拓男, プラグイン/機能拡張, Mozilla, Index, and デベロッパー.\r
- if match:\r
- str = match.group(1)\r
- str = str.replace( "and ", "" )\r
- tags = str.split( ", ")\r
- return tags\r
- else:\r
- return []\r
- \r
- def parse_list(self, html_content, story_infos={}):\r
- """\r
- parse admin.pl's html.\r
- """\r
- bsp = BeautifulSoup(html_content,fromEncoding="utf_8")\r
- bsp_table = bsp.table\r
-\r
- for row in bsp_table.findAll('tr'):\r
- str = unicode(row.prettify(), "utf_8" )\r
- if not str.find(ur"lt_tb_col") == -1:\r
- continue\r
-\r
- datas = row.findAll('td')\r
-\r
- # extract story's url and title\r
- str = unicode(datas[1].prettify(), "utf_8")\r
- str = re.sub( r" \s*", " ", str, re.S )\r
- # print str\r
- match_obj = re.search( r'<a href="(.*)">(.*)</a>', str, re.S )\r
- story_url = match_obj.group(1).strip()\r
- story_title = match_obj.group(2).strip()\r
-\r
- # extract editor\r
- str = unicode(datas[2].prettify(), "utf_8")\r
- str = re.sub( r" \s*", " ", str, re.S )\r
- match_obj = re.search( r'<b>(.*)</b>', str, re.S )\r
- editor = match_obj.group(1).strip()\r
-\r
- # extract PVs\r
- str = unicode(datas[5].prettify(), "utf_8")\r
- str = re.sub( r" \s*", " ", str, re.S )\r
- match_obj = re.search( r'<td>\s*(.*)\s*</td>', str, re.S )\r
- page_views = match_obj.group(1).strip()\r
-\r
- # extract comments\r
- str = unicode(datas[6].prettify(), "utf_8")\r
- str = re.sub( r" \s*", " ", str, re.S )\r
- match_obj = re.search( r'<td>\s*(.*)\s*</td>', str, re.S )\r
- comments = match_obj.group(1).strip()\r
-\r
- # extract datetime\r
- str = unicode(datas[7].prettify(), "utf_8")\r
- str = re.sub( r" \s*", " ", str, re.S )\r
- match_obj = re.search( r'<td>\s*(.*)\s*</td>', str, re.S )\r
- date_time = match_obj.group(1).strip()\r
-\r
- story_info = {\r
- "url":story_url,\r
- "title":story_title,\r
- "editor":editor,\r
- "page_views":page_views,\r
- "comments":comments,\r
- "datetime":date_time,\r
- }\r
- story_infos[story_url] = story_info\r
- return story_infos\r
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+otptools base module - retain session/login info
+"""
+import sys
+import os
+import copy
+import urllib
+import httplib
+import re
+
+from BeautifulSoup import BeautifulSoup
+
+OTP_LOGIN_URL = "http://magazine.sourceforge.jp/login.pl"
+OTP_LOGIN_HOST = "magazine.sourceforge.jp"
+OTP_LOGIN_PATH = "/login.pl"
+
+OTP_LOGIN_PARAM = {
+ "op":"userlogin",
+ "unickname":"",
+ "upasswd":"",
+# "login_temp":0,
+ "userlogin":"ログイン",
+ }
+
+OTP_LIST_PATH = "/admin.pl"
+
+BROWSER = "Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7 (.NET CLR 3.5.30729) "
+
+
+class otptools(object):
+ """
+ Open Tech Press management library core module.
+ """
+
+ def __init__(self, path_cookie, login_name="", login_password=""):
+ """
+ @param path_cookie: path of file which cookie's information stored.
+ @type path_cookie: stinrg
+
+ @param login_name: OTP's login name for use.
+ @type login_name: string
+
+ @param login_password: OTP's login password.
+ @type login_password: string
+ """
+ self.path_cookie = path_cookie
+ self.unickname = login_name
+ self.upasswd = login_password
+ self.cookie = ""
+
+ def get_cookie(self):
+ return self.cookie
+
+ def login(self, user="", passwd=""):
+ login_param = copy.deepcopy(OTP_LOGIN_PARAM)
+
+ if user != "":
+ self.unickname = user
+ if passwd != "":
+ self.upasswd = passwd
+
+ login_param["unickname"] = self.unickname
+ login_param["upasswd"] = self.upasswd
+
+# for item in login_param:
+# print "%s > %s" % (item, login_param[item] )
+
+ encoded_data = urllib.urlencode(login_param)
+# print encoded_data
+
+ headers = {
+ "User-Agent": BROWSER,
+ "Content-type": "application/x-www-form-urlencoded",
+ "Accept": "text/plain",
+ }
+
+ obj = httplib.HTTPConnection(OTP_LOGIN_HOST)
+ obj.request("POST", OTP_LOGIN_PATH, encoded_data, headers)
+ resp = obj.getresponse()
+ headers = resp.getheaders()
+
+# for item in headers:
+# print item
+
+ for header in headers:
+ if header[0] == "set-cookie":
+ str_cookie = header[1]
+ break
+ else:
+ return -1
+
+ self.cookie = str_cookie
+ return 1
+
+ def save_cookie(self):
+ file_obj = open(self.path_cookie, "w")
+ file_obj.write(self.cookie)
+ file_obj.close()
+
+ def load_cookie(self):
+ file_obj = open(self.path_cookie, "r")
+ self.cookie = file_obj.readline()
+ file_obj.close()
+
+ def get_list(self, skips=0):
+ """
+ get otp story list.
+
+ @param skips: index
+ @type skips: int
+ """
+ path = OTP_LIST_PATH
+ if skips != 0:
+ path = path + "?section=&op=list&next=%s" % skips
+
+# sys.stderr.write( path + "\n" )
+ return self._retrieve_html( path )
+
+ def _retrieve_html(self, path):
+ """
+ retrive html from url.
+ """
+ headers = {
+ "User-Agent": BROWSER,
+ "Content-type": "application/x-www-form-urlencoded",
+ "Accept": "text/plain",
+ "Cookie": self.cookie,
+ }
+ obj = httplib.HTTPConnection(OTP_LOGIN_HOST)
+
+ try:
+ obj.request("GET", path, "", headers)
+ except socket.error:
+ # 10060:timed out
+ sys.stderr.write( "socket error: %s" % (path) )
+ return ""
+
+ resp = obj.getresponse()
+ headers = dict(resp.getheaders())
+
+ if resp.status == 302: # redirect
+ return self._retrieve_html( headers["location"] )
+
+ return resp.read()
+
+ def get_tags(self, url):
+ """
+ get story's tags (topics).
+ """
+ html = self._retrieve_html(url)
+ if html == "":
+ return ""
+
+ tags = []
+ match = re.search( r'<meta name="description" content=".* -- article related to (.*)\..*">', html, re.M )
+# 分割されたWebページを1つにつなげる「AutoPager」拡張 -- article related to 森川拓男, プラグイン/機能拡張, Mozilla, Index, and デベロッパー.
+ if match:
+ str = match.group(1)
+ str = str.replace( "and ", "" )
+ tags = str.split( ", ")
+ return tags
+ else:
+ return []
+
+ def parse_list(self, html_content, story_infos={}):
+ """
+ parse admin.pl's html.
+ """
+ bsp = BeautifulSoup(html_content,fromEncoding="utf_8")
+ bsp_table = bsp.table
+
+ for row in bsp_table.findAll('tr'):
+ str = unicode(row.prettify(), "utf_8" )
+ if not str.find(ur"lt_tb_col") == -1:
+ continue
+
+ datas = row.findAll('td')
+
+ # extract story's url and title
+ str = unicode(datas[1].prettify(), "utf_8")
+ str = re.sub( r" \s*", " ", str, re.S )
+ # print str
+ match_obj = re.search( r'<a href="(.*)">(.*)</a>', str, re.S )
+ story_url = match_obj.group(1).strip()
+ story_title = match_obj.group(2).strip()
+
+ # extract editor
+ str = unicode(datas[2].prettify(), "utf_8")
+ str = re.sub( r" \s*", " ", str, re.S )
+ match_obj = re.search( r'<b>(.*)</b>', str, re.S )
+ editor = match_obj.group(1).strip()
+
+ # extract PVs
+ str = unicode(datas[5].prettify(), "utf_8")
+ str = re.sub( r" \s*", " ", str, re.S )
+ match_obj = re.search( r'<td>\s*(.*)\s*</td>', str, re.S )
+ page_views = match_obj.group(1).strip()
+
+ # extract comments
+ str = unicode(datas[6].prettify(), "utf_8")
+ str = re.sub( r" \s*", " ", str, re.S )
+ match_obj = re.search( r'<td>\s*(.*)\s*</td>', str, re.S )
+ comments = match_obj.group(1).strip()
+
+ # extract datetime
+ str = unicode(datas[7].prettify(), "utf_8")
+ str = re.sub( r" \s*", " ", str, re.S )
+ match_obj = re.search( r'<td>\s*(.*)\s*</td>', str, re.S )
+ date_time = match_obj.group(1).strip()
+
+ story_info = {
+ "url":story_url,
+ "title":story_title,
+ "editor":editor,
+ "page_views":page_views,
+ "comments":comments,
+ "datetime":date_time,
+ }
+ story_infos[story_url] = story_info
+ return story_infos
-# otptools README\r
-\r
-\81¡otp_attach.pl\r
-\r
-\81\9b\8aT\97v\r
-\81@otp_attach.pl\82Í\81AOTP\82Ì\8bL\8e\96\97p\82Ì\89æ\91\9c\82ð\83A\83b\83v\83\8d\81[\83h\82·\82é\83c\81[\83\8b\82Å\82 \82é\81B\r
-\r
-\r
-\81\9b\93®\8dì\8fð\8c\8f\r
-\81@Perl v5.8.8\81iActivePerl\81AWindows Vista\81j\82Å\82Ì\93®\8dì\82ð\8am\94F\81B\93®\8dì\82É\82ÍLWP\81ilibwww-perl\81j\83\82\83W\83\85\81[\83\8b\82ª\95K\97v\81B\r
-\r
-\r
-\81\9b\83C\83\93\83X\83g\81[\83\8b\r
-\81@\93K\93\96\82È\83f\83B\83\8c\83N\83g\83\8a\82É\93W\8aJ\8cã\81Aotp_attach.pl\82Ì\89º\8bL\82Ì\8cÂ\8f\8a\82ð\8aÂ\8b«\82É\8d\87\82í\82¹\82Ä\8fC\90³\82·\82é\81B\r
-\r
-----\r
-# \89º\8bL\82Í\8aÂ\8b«\82É\89\9e\82¶\82Ä\93K\93\96\82É\95Ï\8dX\r
-# Otp.pm \82¨\82æ\82ÑOtp\83f\83B\83\8c\83N\83g\83\8a\81iOtp/Attach.pm\81j\82ª\82 \82é\83f\83B\83\8c\83N\83g\83\8a\82ð\8ew\92è\82·\82é\r
-# use lib '~/bin'\r
-use lib 'C:\Users\hirom\bin\otptools';\r
-----\r
-\r
-\r
-\81\9b\8eg\82¢\95û\r
-1.\83\8d\83O\83C\83\93\82·\82é\r
-\81@\81uotp_attach.pl login\81v\82ð\8eÀ\8ds\82·\82é\82Æ\81A\83\86\81[\83U\81[\96¼\82Æ\83p\83X\83\8f\81[\83h\82ª\90q\82Ë\82ç\82ê\82é\81B\90¬\8c÷\82·\82é\82Æ\83J\83\8c\83\93\83g\83f\83B\83\8c\83N\83g\83\8a\82Éotp_cookies.txt\82ª\8dì\90¬\82³\82ê\81A\83N\83b\83L\81[\8fî\95ñ\82ª\95Û\91¶\82³\82ê\82é\81B\r
-\r
- $ otp_attach.pl login\r
-\r
-2. \89æ\91\9c\82ð\83A\83b\83v\83\8d\81[\83h\82·\82é\r
-\r
-\81@\89º\8bL\82Ì\83R\83}\83\93\83h\82Å\89æ\91\9c\82ð\83A\83b\83v\83\8d\81[\83h\82Å\82«\82é\81B\r
-\r
- $ otp_attach.pl attach -i \81\83\8bL\8e\96ID\81\84 -f \81\83\83A\83b\83v\83\8d\81[\83h\82·\82é\83t\83@\83C\83\8b\81\84\r
-\r
-\81@\81\83\8bL\8e\96ID\81\84\82Í\8bL\8e\96\95Ò\8fW\83y\81[\83WURL\82Ì\81usid=\81v\88È\89º\82Ì\95¶\8e\9a\97ñ\82Å\82 \82é\81B\82½\82Æ\82¦\82ÎURL\82ª\r
- http://magazine.sourceforge.jp/developer/admin.pl?op=edit&sid=09/05/12/0852252\r
-\82È\82ç\81A\8bL\8e\96ID\82Í\r
- 09/05/12/0852252\r
-\82Æ\82È\82é\81B\88ê\89ñ\82É1\83t\83@\83C\83\8b\82µ\82©\83A\83b\83v\83\8d\81[\83h\82Å\82«\82È\82¢\82Ì\82Å\81A\95¡\90\94\82Ì\83t\83@\83C\83\8b\82ð\83A\83b\83v\83\8d\81[\83h\82·\82é\8fê\8d\87\82Í\93K\93\96\82É\83V\83F\83\8b\83X\83N\83\8a\83v\83g\93\99\82ð\97\98\97p\82µ\82Ä\82Ù\82µ\82¢\81B\r
-\r
-\97á\81j\r
- for i in *.png; do\r
- otp_attach.pl attach -i \81\83\8bL\8e\96ID\81\84 -f $i\r
- done\r
-\r
-\r
-3. \83\8d\83O\83A\83E\83g\r
-\81@\8dì\8bÆ\8a®\97¹\8cã\81A\89º\8bL\82Ì\83R\83}\83\93\83h\82ð\8eÀ\8ds\82·\82é\82Æ\83\8d\83O\83A\83E\83g\82³\82ê\82é\81B\r
-\r
- $ otp_attach.pl logout\r
-\r
-\r
-\81\9b\92\8d\88Ó\93_\r
-\81@\83G\83\89\81[\8f\88\97\9d\82È\82Ç\82Í\93K\93\96\82È\82Ì\82Å\81A\8eg\97p\8cã\82ÍWeb\83u\83\89\83E\83U\82È\82Ç\82ð\8eg\82Á\82Ä\90³\82µ\82\83A\83b\83v\83\8d\81[\83h\82³\82ê\82½\82©\95K\82¸\8am\94F\82·\82é\82±\82Æ\81B\r
-\r
+# otptools README
+
+\81¡otp_attach.pl
+
+\81\9b\8aT\97v
+\81@otp_attach.pl\82Í\81AOTP\82Ì\8bL\8e\96\97p\82Ì\89æ\91\9c\82ð\83A\83b\83v\83\8d\81[\83h\82·\82é\83c\81[\83\8b\82Å\82 \82é\81B
+
+
+\81\9b\93®\8dì\8fð\8c\8f
+\81@Perl v5.8.8\81iActivePerl\81AWindows Vista\81j\82Å\82Ì\93®\8dì\82ð\8am\94F\81B\93®\8dì\82É\82ÍLWP\81ilibwww-perl\81j\83\82\83W\83\85\81[\83\8b\82ª\95K\97v\81B
+
+
+\81\9b\83C\83\93\83X\83g\81[\83\8b
+\81@\93K\93\96\82È\83f\83B\83\8c\83N\83g\83\8a\82É\93W\8aJ\8cã\81Aotp_attach.pl\82Ì\89º\8bL\82Ì\8cÂ\8f\8a\82ð\8aÂ\8b«\82É\8d\87\82í\82¹\82Ä\8fC\90³\82·\82é\81B
+
+----
+# \89º\8bL\82Í\8aÂ\8b«\82É\89\9e\82¶\82Ä\93K\93\96\82É\95Ï\8dX
+# Otp.pm \82¨\82æ\82ÑOtp\83f\83B\83\8c\83N\83g\83\8a\81iOtp/Attach.pm\81j\82ª\82 \82é\83f\83B\83\8c\83N\83g\83\8a\82ð\8ew\92è\82·\82é
+# use lib '~/bin'
+use lib 'C:\Users\hirom\bin\otptools';
+----
+
+
+\81\9b\8eg\82¢\95û
+1.\83\8d\83O\83C\83\93\82·\82é
+\81@\81uotp_attach.pl login\81v\82ð\8eÀ\8ds\82·\82é\82Æ\81A\83\86\81[\83U\81[\96¼\82Æ\83p\83X\83\8f\81[\83h\82ª\90q\82Ë\82ç\82ê\82é\81B\90¬\8c÷\82·\82é\82Æ\83J\83\8c\83\93\83g\83f\83B\83\8c\83N\83g\83\8a\82Éotp_cookies.txt\82ª\8dì\90¬\82³\82ê\81A\83N\83b\83L\81[\8fî\95ñ\82ª\95Û\91¶\82³\82ê\82é\81B
+
+ $ otp_attach.pl login
+
+2. \89æ\91\9c\82ð\83A\83b\83v\83\8d\81[\83h\82·\82é
+
+\81@\89º\8bL\82Ì\83R\83}\83\93\83h\82Å\89æ\91\9c\82ð\83A\83b\83v\83\8d\81[\83h\82Å\82«\82é\81B
+
+ $ otp_attach.pl attach -i \81\83\8bL\8e\96ID\81\84 -f \81\83\83A\83b\83v\83\8d\81[\83h\82·\82é\83t\83@\83C\83\8b\81\84
+
+\81@\81\83\8bL\8e\96ID\81\84\82Í\8bL\8e\96\95Ò\8fW\83y\81[\83WURL\82Ì\81usid=\81v\88È\89º\82Ì\95¶\8e\9a\97ñ\82Å\82 \82é\81B\82½\82Æ\82¦\82ÎURL\82ª
+ http://magazine.sourceforge.jp/developer/admin.pl?op=edit&sid=09/05/12/0852252
+\82È\82ç\81A\8bL\8e\96ID\82Í
+ 09/05/12/0852252
+\82Æ\82È\82é\81B\88ê\89ñ\82É1\83t\83@\83C\83\8b\82µ\82©\83A\83b\83v\83\8d\81[\83h\82Å\82«\82È\82¢\82Ì\82Å\81A\95¡\90\94\82Ì\83t\83@\83C\83\8b\82ð\83A\83b\83v\83\8d\81[\83h\82·\82é\8fê\8d\87\82Í\93K\93\96\82É\83V\83F\83\8b\83X\83N\83\8a\83v\83g\93\99\82ð\97\98\97p\82µ\82Ä\82Ù\82µ\82¢\81B
+
+\97á\81j
+ for i in *.png; do
+ otp_attach.pl attach -i \81\83\8bL\8e\96ID\81\84 -f $i
+ done
+
+
+3. \83\8d\83O\83A\83E\83g
+\81@\8dì\8bÆ\8a®\97¹\8cã\81A\89º\8bL\82Ì\83R\83}\83\93\83h\82ð\8eÀ\8ds\82·\82é\82Æ\83\8d\83O\83A\83E\83g\82³\82ê\82é\81B
+
+ $ otp_attach.pl logout
+
+
+\81\9b\92\8d\88Ó\93_
+\81@\83G\83\89\81[\8f\88\97\9d\82È\82Ç\82Í\93K\93\96\82È\82Ì\82Å\81A\8eg\97p\8cã\82ÍWeb\83u\83\89\83E\83U\82È\82Ç\82ð\8eg\82Á\82Ä\90³\82µ\82\83A\83b\83v\83\8d\81[\83h\82³\82ê\82½\82©\95K\82¸\8am\94F\82·\82é\82±\82Æ\81B
+
-#!/usr/bin/env python\r
-# -*- coding: utf-8 -*-\r
-"""\r
-otptools base module - retain session/login info\r
-"""\r
-\r
-OTP_LOGIN_URL = "http://slashdot.jp/login.pl"\r
-OTP_LOGIN_HOST = "slashdot.jp"\r
-OTP_LOGIN_PATH = "/login.pl"\r
-\r
-OTP_LOGIN_PARAM = {\r
- "op":"userlogin",\r
- "unickname":"",\r
- "returnto":"http://slashdot.jp",\r
- "upasswd":"",\r
-# "login_temp":0,\r
- "userlogin":"ログイン",\r
- }\r
-\r
-OTP_LIST_PATH = "/admin.pl"\r
-\r
-BROWSER = "Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7 (.NET CLR 3.5.30729) "\r
-\r
-import sys\r
-import os\r
-import copy\r
-import urllib, urllib2\r
-import httplib\r
-\r
-class otptools(object):\r
- """\r
- Open Tech Press management library core module.\r
- """\r
-\r
- def __init__(self, path_cookie, login_name="", login_password=""):\r
- """\r
- @param path_cookie: path of file which cookie's information stored.\r
- @type path_cookie: stinrg\r
-\r
- @param login_name: OTP's login name for use.\r
- @type login_name: string\r
-\r
- @param login_password: OTP's login password.\r
- @type login_password: string\r
- """\r
- self.path_cookie = path_cookie\r
- self.unickname = login_name\r
- self.upasswd = login_password\r
- self.cookie = ""\r
-\r
- def login(self):\r
- """\r
- login to OTP.\r
- """\r
- login_param = copy.deepcopy(OTP_LOGIN_PARAM)\r
- login_param["unickname"] = self.unickname\r
- login_param["upasswd"] = self.upasswd\r
-\r
- for item in login_param:\r
- print "%s > %s" % (item, login_param[item])\r
-\r
- encoded_data = urllib.urlencode(login_param)\r
- print encoded_data\r
-\r
- headers = {\r
- "User-Agent": BROWSER,\r
- "Content-type": "application/x-www-form-urlencoded",\r
- "Accept": "text/plain",\r
- }\r
-\r
-# obj = urllib.urlopen(OTP_LOGIN_URL, encoded_data)\r
-# print obj.info()\r
-\r
- obj = httplib.HTTPConnection(OTP_LOGIN_HOST)\r
- obj.request("POST", OTP_LOGIN_PATH, encoded_data, headers)\r
- resp = obj.getresponse()\r
- headers = resp.getheaders()\r
-\r
- for item in headers:\r
- print item\r
-\r
-# for header in headers:\r
-# if header[0] == "set-cookie":\r
-# str_cookie = header[1]\r
-# break\r
-# else:\r
-# return -1\r
-#\r
-# self.cookie = str_cookie\r
-# return 1\r
-\r
- def save_cookie(self):\r
- file_obj = open(self.path_cookie, "w")\r
- file_obj.write(self.cookie)\r
- file_obj.close()\r
-\r
- def load_cookie(self):\r
- """\r
- load session cookie from file.\r
- """\r
- file_obj = open(self.path_cookie, "r")\r
- self.cookie = file_obj.readline()\r
- file_obj.close()\r
-\r
- def get_list(self):\r
- """\r
- Access admin.pl and retrieve stories list.\r
- """\r
- headers = {\r
- "User-Agent": BROWSER,\r
- "Content-type": "application/x-www-form-urlencoded",\r
- "Accept": "text/plain",\r
- "Cookie": self.cookie,\r
- }\r
- obj = httplib.HTTPConnection(OTP_LOGIN_HOST)\r
- obj.request("POST", OTP_LIST_PATH, "", headers)\r
- resp = obj.getresponse()\r
- headers = resp.getheaders()\r
-\r
- return resp.read()\r
-\r
- \r
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+otptools base module - retain session/login info
+"""
+
+OTP_LOGIN_URL = "http://slashdot.jp/login.pl"
+OTP_LOGIN_HOST = "slashdot.jp"
+OTP_LOGIN_PATH = "/login.pl"
+
+OTP_LOGIN_PARAM = {
+ "op":"userlogin",
+ "unickname":"",
+ "returnto":"http://slashdot.jp",
+ "upasswd":"",
+# "login_temp":0,
+ "userlogin":"ログイン",
+ }
+
+OTP_LIST_PATH = "/admin.pl"
+
+BROWSER = "Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7 (.NET CLR 3.5.30729) "
+
+import sys
+import os
+import copy
+import urllib, urllib2
+import httplib
+
+class otptools(object):
+ """
+ Open Tech Press management library core module.
+ """
+
+ def __init__(self, path_cookie, login_name="", login_password=""):
+ """
+ @param path_cookie: path of file which cookie's information stored.
+ @type path_cookie: stinrg
+
+ @param login_name: OTP's login name for use.
+ @type login_name: string
+
+ @param login_password: OTP's login password.
+ @type login_password: string
+ """
+ self.path_cookie = path_cookie
+ self.unickname = login_name
+ self.upasswd = login_password
+ self.cookie = ""
+
+ def login(self):
+ """
+ login to OTP.
+ """
+ login_param = copy.deepcopy(OTP_LOGIN_PARAM)
+ login_param["unickname"] = self.unickname
+ login_param["upasswd"] = self.upasswd
+
+ for item in login_param:
+ print "%s > %s" % (item, login_param[item])
+
+ encoded_data = urllib.urlencode(login_param)
+ print encoded_data
+
+ headers = {
+ "User-Agent": BROWSER,
+ "Content-type": "application/x-www-form-urlencoded",
+ "Accept": "text/plain",
+ }
+
+# obj = urllib.urlopen(OTP_LOGIN_URL, encoded_data)
+# print obj.info()
+
+ obj = httplib.HTTPConnection(OTP_LOGIN_HOST)
+ obj.request("POST", OTP_LOGIN_PATH, encoded_data, headers)
+ resp = obj.getresponse()
+ headers = resp.getheaders()
+
+ for item in headers:
+ print item
+
+# for header in headers:
+# if header[0] == "set-cookie":
+# str_cookie = header[1]
+# break
+# else:
+# return -1
+#
+# self.cookie = str_cookie
+# return 1
+
+ def save_cookie(self):
+ file_obj = open(self.path_cookie, "w")
+ file_obj.write(self.cookie)
+ file_obj.close()
+
+ def load_cookie(self):
+ """
+ load session cookie from file.
+ """
+ file_obj = open(self.path_cookie, "r")
+ self.cookie = file_obj.readline()
+ file_obj.close()
+
+ def get_list(self):
+ """
+ Access admin.pl and retrieve stories list.
+ """
+ headers = {
+ "User-Agent": BROWSER,
+ "Content-type": "application/x-www-form-urlencoded",
+ "Accept": "text/plain",
+ "Cookie": self.cookie,
+ }
+ obj = httplib.HTTPConnection(OTP_LOGIN_HOST)
+ obj.request("POST", OTP_LIST_PATH, "", headers)
+ resp = obj.getresponse()
+ headers = resp.getheaders()
+
+ return resp.read()
+
+
-\r
-use utf8;\r
-use open IN => ':utf8';\r
-#use open OUT => ':encoding(Shift_JIS)';\r
-use open OUT => ':utf8';\r
-use open ':std';\r
-\r
-\r
-#<DL> <DT><A NAME="62">...\82È\82ç\82È\82¢(reschedule_idle\8aÖ\90\94</A><DD>\82Ù\82ñ\82Ì\8f\82µ\82µ\82©\r
-#\83v\83\89\83C\83I\83\8a\83e\83B\8d·\82ª\96³\82¢\82Æ\82«\82Í\81A\97v\8b\81\82ð\8fo\82³\82È\82¢\r
-#<PRE>.\r
-\r
-\r
-while(my $line = <> ){\r
- chomp $line;\r
- my $string = "";\r
- if( $line =~ m/<DT><A NAME="([0-9]+)">/ ) {\r
- my $num = $1;\r
- $line =~ s/^.*<DD>//;\r
- $string = $line;\r
- while( $line = <> ) {\r
- chomp $line;\r
- if ($line =~ m/(^.*)<PRE>/ ) {\r
- $string .= $1;\r
- last;\r
- } else {\r
- $string .= $line;\r
- }\r
- }\r
- print " '$num' => '$string',\n";\r
- }\r
-}\r
-\r
+
+use utf8;
+use open IN => ':utf8';
+#use open OUT => ':encoding(Shift_JIS)';
+use open OUT => ':utf8';
+use open ':std';
+
+
+#<DL> <DT><A NAME="62">...\82È\82ç\82È\82¢(reschedule_idle\8aÖ\90\94</A><DD>\82Ù\82ñ\82Ì\8f\82µ\82µ\82©
+#\83v\83\89\83C\83I\83\8a\83e\83B\8d·\82ª\96³\82¢\82Æ\82«\82Í\81A\97v\8b\81\82ð\8fo\82³\82È\82¢
+#<PRE>.
+
+
+while(my $line = <> ){
+ chomp $line;
+ my $string = "";
+ if( $line =~ m/<DT><A NAME="([0-9]+)">/ ) {
+ my $num = $1;
+ $line =~ s/^.*<DD>//;
+ $string = $line;
+ while( $line = <> ) {
+ chomp $line;
+ if ($line =~ m/(^.*)<PRE>/ ) {
+ $string .= $1;
+ last;
+ } else {
+ $string .= $line;
+ }
+ }
+ print " '$num' => '$string',\n";
+ }
+}
+
-#!/usr/bin/env python\r
-# -*- coding: utf-8 -*-\r
- \r
-import sys\r
-import os\r
-import codecs\r
-\r
-rootpath = r"C:\Users\hirom\bin\otptools"\r
-sys.path.insert(0, rootpath)\r
-\r
-import wikimarkupper\r
-\r
-\r
-str_usage = "markup.pl hashfile targetfile\n"\r
-path_to_index = "./_markup_index"\r
-\r
-sys.stdin = codecs.getreader('utf_8')(sys.stdin)\r
-sys.stdout = codecs.getwriter('utf_8')(sys.stdout)\r
-\r
-try:\r
-# path_img_hash = sys.argv[1]\r
- path_target = sys.argv[1]\r
-except IndexError:\r
- sys.exit(str_usage)\r
-\r
-markupper = wikimarkupper.WikiMarkupper()\r
-#markupper.make_hashlist(path_img_hash)\r
-markupper.load_index(path_to_index)\r
-\r
-file_target = codecs.open(path_target, "r", "utf_8" )\r
-# file_target = open(path_target, "r")\r
-\r
-markupper.index_add("file", path_target)\r
-markupper.index_add("anchors", [])\r
-\r
-markupper.markup(file_target, 0)\r
-\r
-markupper.save_index(path_to_index)\r
-\r
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys
+import os
+import codecs
+
+rootpath = r"C:\Users\hirom\bin\otptools"
+sys.path.insert(0, rootpath)
+
+import wikimarkupper
+
+
+str_usage = "markup.pl hashfile targetfile\n"
+path_to_index = "./_markup_index"
+
+sys.stdin = codecs.getreader('utf_8')(sys.stdin)
+sys.stdout = codecs.getwriter('utf_8')(sys.stdout)
+
+try:
+# path_img_hash = sys.argv[1]
+ path_target = sys.argv[1]
+except IndexError:
+ sys.exit(str_usage)
+
+markupper = wikimarkupper.WikiMarkupper()
+#markupper.make_hashlist(path_img_hash)
+markupper.load_index(path_to_index)
+
+file_target = codecs.open(path_target, "r", "utf_8" )
+# file_target = open(path_target, "r")
+
+markupper.index_add("file", path_target)
+markupper.index_add("anchors", [])
+
+markupper.markup(file_target, 0)
+
+markupper.save_index(path_to_index)
+