From 625a24207bf75209a736e52949d84b4f45bd69c9 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Sat, 16 Jul 2022 00:46:36 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BA=D0=BE=D1=81=D1=8F=D0=BA=20=D1=81=20=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=BE=D1=81=D1=82=D1=8F=D0=BC=D0=B8=20=D1=81=D0=BB?= =?UTF-8?q?=D0=BE=D0=B1=D0=BE=D0=B4=D1=8B,=20=D1=82=D0=B5=D1=81=D1=80?= =?UTF-8?q?=D0=B8=D1=80=D1=83=D0=B5=D0=BC=20=D0=BD=D0=B0=20=D1=82=D0=B5?= =?UTF-8?q?=D0=BA=D1=83=D1=89=D0=B5=D0=B9=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8?= =?UTF-8?q?=D0=B3=D1=83=D1=80=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/config.php | 2 +- core/cron.php | 17 +---------------- core/lib/Core/MQTasks.class.php | 25 ++++++++++++------------- core/lib/Core/Models/MQ.class.php | 2 +- 4 files changed, 15 insertions(+), 31 deletions(-) diff --git a/core/config.php b/core/config.php index 15183a3..16a9729 100644 --- a/core/config.php +++ b/core/config.php @@ -111,5 +111,5 @@ /** * Флаг использования логирования */ - const USE_LOG = false; + const USE_LOG = true; diff --git a/core/cron.php b/core/cron.php index 1f9395b..4446ec8 100644 --- a/core/cron.php +++ b/core/cron.php @@ -34,19 +34,4 @@ exec('(php -f ' . __DIR__ . '/runtime/threadsWorker.php & ) >> /dev/null 2>&1'); - // Каждые 10 минут добавляем в очередь задание на проверку новостей слободы и отправку в телегу - $cacheId = md5('cron_myslo'); - $runMyslo = false; - if (Cache::check($cacheId) && $cronMyslo = Cache::get($cacheId)) { - if ((time() - (int)$cronMyslo) > 600) { - $runMyslo = true; - Cache::set($cacheId, time()); - } - } else { - $runMyslo = true; - Cache::set($cacheId, time()); - } - - if ($runMyslo === true) { - $result = (new MQ())->setAttempts(3)->setPriority(3)->setCheckDuplicates(true)->createTask('Core\MQTasks', 'getMySLO'); - } \ No newline at end of file + $result = (new MQ())->setAttempts(3)->setPriority(1)->setCheckDuplicates(true)->createTask('Core\MQTasks', 'getMySLO'); diff --git a/core/lib/Core/MQTasks.class.php b/core/lib/Core/MQTasks.class.php index d1edaf1..6b817c7 100644 --- a/core/lib/Core/MQTasks.class.php +++ b/core/lib/Core/MQTasks.class.php @@ -253,12 +253,10 @@ DELETE from `jokes` WHERE `jokes`.id not in (SELECT id FROM t_temp);' public static function getMySLO() { - $cacheId = md5('getMySLO_criminal'); - if (Cache::check($cacheId)) { - $oldLink = Cache::get($cacheId); - } else { - $oldLink = ''; - } + $result = 'Нет данных для обновления'; + /** @var DB $DB */ + $DB = DB::getInstance(); + $file = file_get_contents('https://myslo.ru/news/criminal'); $file = preg_match_all('/"item width-100-tiny">(.*?)
/us', $file, $file2); @@ -273,10 +271,10 @@ DELETE from `jokes` WHERE `jokes`.id not in (SELECT id FROM t_temp);' preg_match_all('/" href="(.*?)">/us', $file2, $link); $link = 'https://myslo.ru' . trim($link[1][0]); + $hash = md5($link); + $res = $DB->query('SELECT * FROM myslo WHERE hash="' . $hash . '"'); + if (!$res) { - if ($oldLink !== $link) { - sendTelegram('OLD (' . strlen($oldLink) . '): ' . $oldLink . PHP_EOL . 'NEW (' . strlen($link) . '): ' . $link); - sendTelegram('Обнаружен новый пост'); $full = file_get_contents($link); preg_match_all('/

(.*?)<\/p><\/div>/us', $full, $lidArticle); @@ -303,16 +301,17 @@ DELETE from `jokes` WHERE `jokes`.id not in (SELECT id FROM t_temp);' $post = '' . $title . '' . PHP_EOL . $lidArticle . PHP_EOL . $fullArticle; $post .= PHP_EOL . 'Подробнее'; + $telegram = new \Core\ExternalServices\TelegramSender(TELEGRAM_BOT_TOKEN); $telegram->setChat('-1001789206618'); $res = $telegram->sendPhoto($tmpFile, $post); + sendTelegram($post); @unlink($tmpFile); - Cache::set($cacheId, trim($link)); - return $res; + $itemId = $DB->addItem('myslo', ['hash' => $hash, 'title' => $title]); + + return print_r($res, true);//'Добавлен новый элемент с ID ' . $itemId; } else { return 'Обновление не требуется'; } - - return $res; } } \ 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 80252ef..3296d51 100644 --- a/core/lib/Core/Models/MQ.class.php +++ b/core/lib/Core/Models/MQ.class.php @@ -531,7 +531,7 @@ 'in_progress' => self::VALUE_N, 'attempts' => '0', 'attempts_limit' => $this->runNow ? '1' : $this->attempts, // Если запускаем немедленно, то попытка одна - 'class' => !empty($class) ? addslashes($class) : '', + 'class' => !empty($class) ? $class : '', 'method' => $method, 'priority' => $priority, 'params' => $params,