foltia ANIME LOCKER用 予約重複 チェックツール
2025/08/27 22:34
そこで、予約一覧から予約時刻が重複している番組を抽出するツールを作成しました。
Perl で書いてあります。cron で実行すると重複予約があるときだけメールで知らせてくれるように出来ます。
ソース
#!/usr/bin/env perl
use strict;
use warnings;
use HTTP::Tiny;
our $FOLTIA_HOST = 'http://localhost:80';
get_reservation_table('/reservation/');
exit;
sub get_reservation_table {
my ($path) = @_;
my $resp = HTTP::Tiny->new->get($FOLTIA_HOST. $path);
if ($resp->{success}) {
my $body = $resp->{content};
while ($body =~ m|<tr.+?</tr>|sg) {
my $rec = $&;
$rec =~ s/<br>|\n|\r//g;
my ($id) = $rec =~ m|id="(-\d+)"|;
next unless $id;
my ($station) = $rec =~ m|<td class="station">(.+?)</td>|;
my ($date) = $rec =~ m|<td class="date">(.+?)</td>|;
my ($title) = $rec =~ m|<td>(.+?)</td>|;
die "放送局・日時・番組名が取得できませんでした. rec=$rec" unless $station && $date && $title;
print "$id $date $station $title\n" if check_overwrap($id);;
}
get_reservation_table($1) if $body =~ m|<a rel=next href="(.+?)" >|;
} else {
die "予約一覧が取得できませんでした. get=$FOLTIA_HOST$path";
}
}
sub check_overwrap {
my ($id) = @_;
my $api_url = "${FOLTIA_HOST}/reservation/reservation_overwrap_chk_api.php?p=$id";
my $resp = HTTP::Tiny->new->get($api_url);
if ($resp->{success}) {
my $body = $resp->{content};
if( my ($overwrap) = $body =~ /"overwrap":"(.*?)"/ ) {
return $overwrap;
} else {
die "overwrap 文字列が取得できませんでした. api_url=$api_url";
}
} else {
die "overwrap が取得できませんでした. api_url=$api_url";
}
}