From 2a59c4c1d8933adaa51407ddc34c7415921a2c75 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Sun, 10 Jul 2022 11:30:44 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D0=BE=D0=B4=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=B0=D1=80=D1=81=D0=B8=D0=BD?= =?UTF-8?q?=D0=B3=D0=B0=20=D0=B0=D0=BD=D0=B5=D0=BA=D1=82=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/cron.php | 1 - core/lib/Core/MQTasks.class.php | 32 +++++++++++++++++++++++++++++++ core/lib/Core/Models/MQ.class.php | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/core/cron.php b/core/cron.php index 2ea2bf5..79bc61c 100644 --- a/core/cron.php +++ b/core/cron.php @@ -12,7 +12,6 @@ try { (new MQ())->run(); - Core\MQTasks::sendBash();// test bash loading } catch (Throwable $t) { SystemFunctions::sendTelegram('CRON: Произошла ошибка' . PHP_EOL . $t->getMessage() . PHP_EOL . 'File: ' . $t->getFile() . PHP_EOL . 'Line: ' . $t->getLine()); echo 'Error: ' . $t->getMessage() . ' / line: ' . $t->getLine(); diff --git a/core/lib/Core/MQTasks.class.php b/core/lib/Core/MQTasks.class.php index 55aa836..9ec320a 100644 --- a/core/lib/Core/MQTasks.class.php +++ b/core/lib/Core/MQTasks.class.php @@ -145,4 +145,36 @@ sleep(5); return 'bashMeta: Добавлено ' . $i . ', обновлено ' . $j . ' записей из ' . count($result); } + + public static function anekdot() + { + /** @var DB $DB */ + $DB = DB::getInstance(); + + $file = file_get_contents('https://www.anekdot.ru/rss/randomu.html'); + $file = explode('JSON.parse(\'', $file)[1]; + $file = explode('\');', $file)[0]; + $file = stripcslashes($file); + $arJokes = json_decode($file); + + if(empty($arJokes)) { + throw new CoreException('Ошибка получения данных с сайта'); + } + $i = 0; + foreach($arJokes as $joke) { + $hash = md5($joke); + $joke = str_replace('
', PHP_EOL, $joke); + $res = $DB->query('SELECT * FROM jokes WHERE hash="' . $hash . '"'); + if (!$res) { + $i++; + $itemId = $DB->addItem('jokes', ['hash' => $hash, 'text' => $joke]); + //sendTelegram('Добавлена шутка ID ' . $itemId . '' . PHP_EOL . $joke); + } + } + + + + sleep(2); + return 'Добавлено ' . $i . ' шуток из ' . count($arJokes); + } } \ No newline at end of file diff --git a/core/lib/Core/Models/MQ.class.php b/core/lib/Core/Models/MQ.class.php index c1667ae..9586084 100644 --- a/core/lib/Core/Models/MQ.class.php +++ b/core/lib/Core/Models/MQ.class.php @@ -61,7 +61,7 @@ /** * Лимит количества одновременно выполняемых задач */ - const WORKERS_LIMIT = 10; + const WORKERS_LIMIT = 2; /** * @var DB|null $DB Объект базы