Last active
November 30, 2020 16:14
-
-
Save okumurakengo/aca8a42083c0cd1aa7feb34f193d4923 to your computer and use it in GitHub Desktop.
nitterのrssのプロキシ。slackのrssリーダーが何度取りに来ても、9時以降に1日1度しかnitterにアクセスしない。レンタルサーバー などに設置して使う。
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 | |
if (!array_key_exists('category', $_GET)) { | |
exit('¯\_(ツ)_/¯'); | |
} | |
date_default_timezone_set('Asia/Tokyo'); | |
$pdo = new PDO('sqlite:db.sqlite'); | |
$pdo->exec(<<<'EOL' | |
create table if not exists tbl_rss ( | |
id integer not null primary key, | |
body text not null, | |
last_date datetime not null | |
); | |
EOL); | |
$now = new DateTimeImmutable; | |
if ($now > $now->setTime(9, 0, 0)) { | |
$borderDateTime = $now->setTime(9, 0, 0); | |
} else { | |
$borderDateTime = $now->modify('-1 day')->setTime(9, 0, 0); | |
} | |
$stmt = $pdo->prepare('select body, last_date from tbl_rss where id = ?'); | |
$stmt->execute([$_GET['category']]); | |
$res = $stmt->fetch(PDO::FETCH_NUM); | |
[$body, $lastDateTimeString] = $res ?: ['', null]; | |
if (is_null($lastDateTimeString) or $borderDateTime > new DateTimeImmutable($lastDateTimeString)) { | |
file_put_contents((new DateTimeImmutable())->format('YmdHis') . '.log',json_encode(['category' => $_GET['category']])); | |
switch($_GET['category']) { | |
case 1: | |
// 社畜ちゃん | |
$body = file_get_contents('https://nitter.net/vitaone_/search/rss?f=tweets&q=最新話&f-images=on&e-nativeretweets=on'); | |
break; | |
case 2: | |
// ハンバーガーちゃん | |
$body = file_get_contents('https://nitter.net/HundredBurger/search/rss?f=tweets&q=できた+OR+出来た+OR+出来ました&f-media=on&e-nativeretweets=on'); | |
break; | |
default: | |
exit('¯\_(ツ)_/¯'); | |
} | |
$stmt = $pdo->prepare('replace into tbl_rss values(?,?,?)'); | |
$stmt->execute([$_GET['category'], $body ?? '', $now->format('Y-m-d H:i:s')]); | |
} | |
header('Content-Type: application/rss+xml; charset=utf-8'); | |
echo $body; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment