Last active
September 25, 2019 07:11
-
-
Save tateisu/920a26d73ebdfb485adac07a0f783c32 to your computer and use it in GitHub Desktop.
suspend user who in pawoo.net and his note like 'めったにPawooを使いません'.
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
#!/usr/bin/perl -- | |
use strict; | |
use warnings; | |
use utf8; | |
# mastodonのdockerコンテナの rails console はreadline がUS-ASCIIなので、文字列リテラルはエスケープが必要 | |
sub escapeNonAscii($){ | |
my($a) = @_; | |
$a =~ s/([\x{80}-\x{fffff}])/"\\u{".sprintf("%x",ord $1)."}"/ge; | |
$a; | |
} | |
my $phrase = escapeNonAscii quotemeta 'めったにPawooを使いません'; | |
# rails console に送るコマンドはワンライナーにする必要がある | |
my $cmd = <<"END"; | |
Account | |
.where(domain:'pawoo.net',suspended_at:nil) | |
.where('note like ?',"%$phrase%") | |
.map{ |account| | |
SuspendAccountService.new.call(account, reserve_email: false) | |
;"#{account.username},#{account.domain}" | |
} | |
END | |
# ワンライナーを整形する | |
$cmd =~ s/^\s*#.+/ /gm; | |
$cmd =~ s/[\s\x0d\x0a]+/ /g; | |
# ワンライナーをdockerコンテナのrails console に送る | |
open(my $fh,"|-","docker-compose run --rm web bundle exec rails console") or die $!; | |
print $fh $cmd; | |
close($fh) or die $!; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rails console 直打ちなら
Account .where(domain:'pawoo.net',suspended_at:nil) .where('note like ?',"%\u{3081}\u{3063}\u{305f}\u{306b}Pawoo\u{3092}\u{4f7f}\u{3044}\u{307e}\u{305b}\u{3093}%") .map{ |account| SuspendAccountService.new.call(account, reserve_email: false) ;"#{account.username},#{account.domain}" }