|
||
commonsにあるくるみんマークだが、これはマズいんじゃないのか? 井戸端や会話ページでは私の指摘に対して会話してくれないわけだが、まあ、他の書き込みをみれば問題ないと解釈しているようで。
とりあえず、厚生労働省に問い合わせてみた。
movepages.py, jawn | |
短信をウィキニュース名前空間から短信名前空間に移動するスクリプト。要約欄をコマンドラインから指定しているのでリビジョン5200以降のmovepages.pyが必要。
年とか月とかがあることを想定していなかったのでいろいろアレだが、気にしない。年については移動させてないので何とかする必要あり。
#!/usr/bin/perl use strict; use warnings; my $s_year = 2006; my $s_month = 8; my $s_day = 16; my $e_year = 2006; my $e_month = 8; my $e_day = 31; my $script = '/path/to/pywikipedia/movepages.py'; my $logfile = 'news-move-tanshin.log'; my $time = 60; my $t_family = 'wikinews'; my $t_lang = 'ja'; my $summary = '短信名前空間への移動'; # ------------------------------ my $year = $s_year; my $month = $s_month; my $day = $s_day; my @last_day = ('31','28','31','30','31','30','31','31','30','31','30','31'); # year for my $year ($s_year..$e_year) { # month my $y_s_month = ( $year == $s_year ) ? $s_month : 1; my $y_e_month = ( $year == $e_year ) ? $e_month : 12; for my $month (${y_s_month}..${y_e_month}){ # ------------------ my $month_date = sprintf "%d年/%d月",$year,$month; my $from_page = "ウィキニュース:短信/${month_date}"; my $to_page = "短信:${month_date}"; my $command = qq@/usr/bin/python ${script} -family:${t_family} -lang:${t_lang} -putthrottle:${time} -log:${logfile} -summary:"${summary}" -from:"${from_page}" -to:"${to_page}"@; print $command . "\n"; system ($command); sleep (60); # ------------------ # day my $m_s_day = ( $year == $s_year && $month == $s_month ) ? $s_day : 1; my $m_e_day = 0; if( $year == $e_year && $month == $e_month ){ $m_e_day = $e_day; } else { $m_e_day = $last_day[$month-1]; if( $month == 2 && is_leap_year($year) ){ $m_e_day = 29 } } for my $day (${m_s_day}..${m_e_day}) { # ------------------ my $date = sprintf "%d年/%d月/%d日",$year,$month,$day; # print $date; my $from_page = "ウィキニュース:短信/${date}"; my $to_page = "短信:${date}"; my $command = qq@/usr/bin/python ${script} -family:${t_family} -lang:${t_lang} -putthrottle:${time} -log:${logfile} -summary:"${summary}" -from:"${from_page}" -to:"${to_page}"@; print $command . "\n"; system ($command); sleep (60); # ------------------ } } } sub is_leap_year { my $target_year = shift; if( ( ( $target_year % 4 == 0 ) && ( $target_year % 100 != 0 ) ) || ( $target_year % 400 == 0 ) ){ return 1; }else{ return 0; } } # ---------------------------------- # The MIT License # # Copyright (c) 2008 IWAI, Masaharu # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE.
replace.py | |
「バー」の一部を「バー (酒場)」に分割したときにリンクを変更させるために走らせた例。replace.pyは事前にどの記事のどの部分を置換するのかを対話式で入力した後で置換処理を開始するので最初の入力は面倒だったが後は数時間放置という感じ。
なお、これだけだと全部は無理なのでボットを走らせた後に手作業での実施も併用。
#!/bin/sh ## config . ./config.sh LOGFILE=bar-link.log SUMMARY=リンク先変更 BEFORE_TEXT='[[バー]]' AFTER_TEXT='[[バー (酒場)|バー]]' cd $BOTDIR python replace.py -putthrottle:$TIME -summary:"$SUMMARY" -log:$LOGFILE -ref:バー "$BEFORE_TEXT" "$AFTER_TEXT"
category.py | |
カテゴリを改名したときに各記事のカテゴリを差し替えるときはcategory.pyが使える。
以下は「Category:XXベース」を「Category:XXベースのカクテル」に差し替えたときの例。正規表現より変数を使う方が楽なのでこんなループを回した。
#!/bin/sh ## config . ./config.sh LOGFILE=category_cocktails.log cd $BOTDIR array=("ウォッカ" "ジン" "テキーラ" "ブランデー" "ラム" "リキュール" "ワイン") for base in "${array[@]}" do SUMMARY=カテゴリの差し替え([[:Category:$baseベース]]から[[:Category:$baseベースのカクテル]])([[Wikipedia:ウィキプロジェクト_酒]]による移動) echo $SUMMARY python category.py -putthrottle:$TIME -summary:$SUMMARY -log:$LOGFILE move -from:"$baseベース" -to:"$baseベースのカクテル" done
全般 | |
Help:Pywikipediabotを読んでpywikipediabotを使えるようにした。環境はVineSeedでlocaleはja_JP.utf8。
Pythonはよくわからないのだが、デフォルトの文字符号化方式を設定しないとダメだったので、/usr/lib/python2.4/site-packages/sitecustomize.pyに設定。
import sys sys.setdefaultencoding('utf-8')
また、シェルスクリプト経由で実行することにしたので、共通する設定を/home/foo/barにconfig.shとして用意する。今後実行のためのシェルスクリプトを掲載する場合はこれを読み込んで実行する。
LC_ALL=ja_JP.utf8 LANG=ja_JP.utf8 BOTDIR=/path/to/pywikipedia FILEDIR=/home/foo/bar/files TIME=60