[+] метод для парсинга ПОДСЛУШАНО
This commit is contained in:
1 parent
e3fbacb6b5
commit
636979e51c
8 files changed
+292
-43
No files matched your search
@@ -26,6 +26,7 @@
|
||||
use Core\Helpers\Thumbs;
|
||||
use Core\ExternalServices\TelegramSender;
|
||||
use Core\Models\DB;
|
||||
use Core\Models\MQ;
|
||||
|
||||
class MQTasks
|
||||
{
|
||||
@@ -449,4 +450,62 @@ DELETE from `jokes` WHERE `jokes`.id not in (SELECT id FROM t_temp);'
|
||||
return file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/uploads/screens/' . $url . ' .png', $image);
|
||||
}
|
||||
|
||||
|
||||
public static function getStory($from = null)
|
||||
{
|
||||
$tableName = 'podslyshano';
|
||||
$link = 'https://podslyshano.com/api/v3.5/posts';
|
||||
if (!empty($from) && $from !== '') {
|
||||
$link .= '?from=' . $from;
|
||||
}
|
||||
$response = file_get_contents($link);
|
||||
if (empty($response)) {
|
||||
throw new CoreException('Не удалось получить содержимое');
|
||||
}
|
||||
|
||||
try {
|
||||
$response = json_decode($response, true, 512, JSON_THROW_ON_ERROR);
|
||||
} catch(\Throwable $e) {
|
||||
throw new CoreException($e->getMessage());
|
||||
}
|
||||
|
||||
if (empty($response['posts'])) {
|
||||
throw new CoreException('Постов по данной выборке не найдено');
|
||||
}
|
||||
|
||||
$result = [];
|
||||
$lastId = null;
|
||||
/** @var DB $DB */
|
||||
$DB = DB::getInstance();
|
||||
foreach ($response['posts'] as $post) {
|
||||
if ($post['type'] !== 'post') {
|
||||
continue;
|
||||
}
|
||||
if ($DB->getItem($tableName, ['post_id' => (int)$post['id']])) {
|
||||
continue;
|
||||
}
|
||||
$DB->query('SET NAMES \'utf8mb4\'');
|
||||
$result[] = $DB->addItem(
|
||||
$tableName, [
|
||||
'type' => $post['type'],
|
||||
'post_id' => (int)$post['id'],
|
||||
'category_id' => (int)$post['category_id'],
|
||||
'category_name' => $post['category_name'],
|
||||
'category_slug' => $post['category_slug'],
|
||||
'likes_count' => (int)$post['likes_count'],
|
||||
'created_at' => $post['created_at'],
|
||||
'image_uri' => $post['image_uri'],
|
||||
'note' => addslashes($post['note']),
|
||||
]
|
||||
);
|
||||
$lastId = (int)$post['id'];
|
||||
}
|
||||
|
||||
if ($lastId !== null) {
|
||||
exec('(php -f ' . $_SERVER['DOCUMENT_ROOT'] . '/core/runtime/podslyshano.php "' . $lastId . '" & ) >> /dev/null 2>&1');
|
||||
}
|
||||
|
||||
return 'Добавлено постов: ' . count($result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2022 Roman Grinko <rsgrinko@gmail.com>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Исполнительный файл подслушано
|
||||
*/
|
||||
@ignore_user_abort(true);
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '512M');
|
||||
|
||||
require_once __DIR__ . '/init.php';
|
||||
|
||||
use Core\Models\MQ;
|
||||
$fromPostId = $argv[1];
|
||||
//sleep(5);
|
||||
|
||||
(new MQ())->setPriority(9)->setAttempts(3)->createTask('Core\MQTasks', 'getStory', [$fromPostId]);
|
||||
Reference in new issue
Block a user