Created
February 12, 2013 20:47
-
-
Save ikegami-yukino/4773240 to your computer and use it in GitHub Desktop.
1500ったーのCSVから本文だけ取り出す(RTは除外)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 1500ったーのCSVから余分な情報をカット | |
* | |
* RTを含むツイート、行頭の1500ったーのナンバーとユーザー名と投稿日、行末の引用元URL | |
* 文中のURL、返信宛先(@fooとか)をカット | |
* | |
* USAGE | |
* このスクリプトと同じディレクトリに1500ったーのCSVを置き | |
* コマンドプロンプトやターミナルから以下のとおり入力 | |
* | |
* php parse1500ter.php 1500ったーのCSVファイル名 出力先ファイル名 | |
* | |
* ※Windowsの場合は環境変数でPATHにPHPのディレクトリを追加していることが前提 | |
* | |
* 例 | |
* php parse1500ter.php input.csv output.csv | |
*/ | |
error_reporting(-1); | |
$start_time = microtime(true); | |
$inputfile = $argv[1]; | |
$outputfile = $argv[2]; | |
$rules = array( | |
#"RTQT" => "/.*(RT|QT) .*(\n|\r|$)/", // RTやQTを含むツイート | |
#"num_user_date" => '/"[0-9]{1,4}",.*:[0-9]{2}","/', // 行頭の1500ったーの番号とユーザー名、投稿日 | |
#"cite_url" => '/","http:.*"/', // 行末の引用元URL | |
"url" => "/https?:\/\/[A-z0-9&_\.\?\=\:\%\/]*/", // URL | |
#"replyuser" => "/\@[A-z0-9_:]*/", // @ユーザー | |
); | |
echo $inputfile." からRTの行を削除し、ツイートのみを抽出します。\n"; | |
$content = file_get_contents($inputfile); | |
foreach($rules as $rule){ | |
$content = preg_replace($rule,"",$content); | |
} | |
file_put_contents($outputfile,$content); | |
$taken_time = microtime(true) - $start_time; | |
printf ("処理が終了しました。結果は %s に出力します。\n処理時間 %f 秒\n", $outputfile, $taken_time); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment