Last active
May 13, 2020 07:15
-
-
Save 5l/9d46ac260706750158e86a6eaf3dac47 to your computer and use it in GitHub Desktop.
twitterからチケをリアルタイムエゴサするツール(PHPCLI)
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 | |
# 通知先のTwitterID | |
$notif = "@sora_haruyasumi"; | |
# 検索条件に使う公演名またはアーティスト名の名称(複数ある場合カンマ区切り) | |
$title = "TrySail,トラセ"; | |
# 複数公演がある場合、絞り込むための具体的な文字列(複数ある場合カンマ区切り / 無い場合は空欄) | |
$match = "茨城,文化センター,Ibaraki,4/1,水戸,県立,県民"; | |
# ツイートするTwitterアカウントのCK,CS,AK,AT | |
$to = new TwistOAuth("ConsumerKey", | |
"ConsumerSecret", | |
"AccessToken", | |
"AccessTokenSecret"); | |
set_time_limit(0); | |
date_default_timezone_set('Asia/Tokyo'); | |
require_once("TwistOAuth.php"); | |
$match = str_replace(",", "|", $match); | |
while(true){ | |
try{ | |
$to->streaming( | |
"statuses/filter", | |
function($status) use ($to){ | |
global $notif, $match; | |
if(isset($status->text) && !isset($status->retweeted_status)){ | |
$screen_name = $status->user->screen_name; | |
$dates = date('Y-m-d H:i:s', strtotime($status->created_at)); | |
$name = $status->user->name; | |
$tweet = $status->text; | |
$id_str = $status->id_str; | |
if(preg_match("#{$match}#i", $tweet) && | |
preg_match("#チケ|円|¥|売|買|求|購入|定価|手数料|譲|余|交換|取引|ticket_bot|+α#i", $tweet)){ | |
# 通知するツイート内容 | |
$mes = "{$notif} https://twitter.com/a/status/{$id_str}"; | |
$res = $to->post("statuses/update", array("status" => $mes)); | |
e("[OK] {$name}@{$screen_name} {$dates} {$id_str}\n{$tweet}\n"); | |
}else{ | |
e("[NG] {$name}@{$screen_name} {$dates} {$id_str}\n{$tweet}\n"); | |
} | |
flush(); | |
} | |
}, array('track' => $title) | |
); | |
}catch(TwistException $e){ | |
echo $e->getMessage(); | |
} | |
} | |
function e($str){ | |
echo mb_convert_encoding($str . PHP_EOL, "SJIS", "auto"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment