Automation/app/Controllers/CLI/Yamap.php
2024-09-05 20:13:31 +09:00

66 lines
2.4 KiB
PHP

<?php
namespace App\Controllers\CLI;
use App\Controllers\BaseController;
use App\Entities\Mangboard\FreeboardEntity;
use App\Libraries\Mangboard\FreeboardLibrary;
use App\Libraries\MyCrawlerLibrary;
use App\Libraries\MyStorage\MyStorageFileLibrary;
use App\Libraries\MyWebLibrary;
use App\Libraries\YamapLibrary;
class Yamap extends BaseController
{
public function crawler(...$params): bool
{
try {
$isDebug = in_array("debug", $params);
$nickname = getenv("yamap.view.default.nickname");
$datas = [];
//Yamap사이트에서 자유게시판에서 최근 게시물 데이터 가져오기
if (!in_array("skip_build", $params)) {
$myWeb = new MyWebLibrary(getenv('yamap.host.url'));
$storage = new MyStorageFileLibrary(WRITEPATH . "uploads");
$storage->setPath("Yamap");
$crawler = new MyCrawlerLibrary();
$yamap = new YamapLibrary();
$yamap->setDebug($isDebug);
$yamap->setMyWeb($myWeb);
$yamap->setMyStorage($storage);
$yamap->setMyCrawler($crawler);
list($nickname, $mediaInfos, $mediaTags) = $yamap->build();
}
//2. 사이트 로그인 처리
if (!in_array("skip_login", $params)) {
$myWeb = new MyWebLibrary(getenv('daemonidc.host.url'));
$myWeb->setDebug($isDebug);
$myWeb->login(
getenv('daemonidc.login.url'),
getenv('daemonidc.login.user_id'),
getenv('daemonidc.login.user_password')
);
}
//3. 망보드 일반게시판에 게시물 등록 처리
if (!in_array("skip_create", $params)) {
$mangboard = new FreeboardLibrary();
$mangboard->setDebug($isDebug);
$entity = new FreeboardEntity();
//미디어관련용
$entity->setTitle($nickname);
$entity->setContent(is_array($mediaTags) ? implode("\n", $mediaTags) : $mediaTags);
$mangboard->create($entity);
}
log_message("notice", "완료되었습니다.");
return true;
} catch (\Exception $e) {
log_message("error", $e->getMessage());
return false;
}
}
}