исправлен косяк с новостями слободы, тесрируем на текущей конфигурации
This commit is contained in:
1 parent
c2031769cf
commit
625a24207b
4 files changed
+15
-31
No files matched your search
+1
-1
@@ -111,5 +111,5 @@
|
||||
/**
|
||||
* Флаг использования логирования
|
||||
*/
|
||||
const USE_LOG = false;
|
||||
const USE_LOG = true;
|
||||
|
||||
+1
-16
@@ -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');
|
||||
}
|
||||
$result = (new MQ())->setAttempts(3)->setPriority(1)->setCheckDuplicates(true)->createTask('Core\MQTasks', 'getMySLO');
|
||||
@@ -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">(.*?)<div class="clear">/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('/<div class="h3 lid"><p>(.*?)<\/p><\/div>/us', $full, $lidArticle);
|
||||
@@ -303,16 +301,17 @@ DELETE from `jokes` WHERE `jokes`.id not in (SELECT id FROM t_temp);'
|
||||
$post = '<b>' . $title . '</b>' . PHP_EOL . $lidArticle . PHP_EOL . $fullArticle;
|
||||
$post .= PHP_EOL . '<a href="' . $link . '">Подробнее</a>';
|
||||
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user