новый метод задания для парсинга анектотов
This commit is contained in:
1 parent
265ffda21d
commit
2a59c4c1d8
3 files changed
+33
-2
No files matched your search
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
(new MQ())->run();
|
(new MQ())->run();
|
||||||
Core\MQTasks::sendBash();// test bash loading
|
|
||||||
} catch (Throwable $t) {
|
} catch (Throwable $t) {
|
||||||
SystemFunctions::sendTelegram('CRON: Произошла ошибка' . PHP_EOL . $t->getMessage() . PHP_EOL . 'File: ' . $t->getFile() . PHP_EOL . 'Line: ' . $t->getLine());
|
SystemFunctions::sendTelegram('CRON: Произошла ошибка' . PHP_EOL . $t->getMessage() . PHP_EOL . 'File: ' . $t->getFile() . PHP_EOL . 'Line: ' . $t->getLine());
|
||||||
echo 'Error: ' . $t->getMessage() . ' / line: ' . $t->getLine();
|
echo 'Error: ' . $t->getMessage() . ' / line: ' . $t->getLine();
|
||||||
|
|||||||
@@ -145,4 +145,36 @@
|
|||||||
sleep(5);
|
sleep(5);
|
||||||
return 'bashMeta: Добавлено ' . $i . ', обновлено ' . $j . ' записей из ' . count($result);
|
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('<br>', PHP_EOL, $joke);
|
||||||
|
$res = $DB->query('SELECT * FROM jokes WHERE hash="' . $hash . '"');
|
||||||
|
if (!$res) {
|
||||||
|
$i++;
|
||||||
|
$itemId = $DB->addItem('jokes', ['hash' => $hash, 'text' => $joke]);
|
||||||
|
//sendTelegram('<b>Добавлена шутка ID ' . $itemId . '</b>' . PHP_EOL . $joke);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sleep(2);
|
||||||
|
return 'Добавлено ' . $i . ' шуток из ' . count($arJokes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
/**
|
/**
|
||||||
* Лимит количества одновременно выполняемых задач
|
* Лимит количества одновременно выполняемых задач
|
||||||
*/
|
*/
|
||||||
const WORKERS_LIMIT = 10;
|
const WORKERS_LIMIT = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var DB|null $DB Объект базы
|
* @var DB|null $DB Объект базы
|
||||||
|
|||||||
Reference in new issue
Block a user