| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace app\command;
- use app\model\dynasty\DynastyAuthor;
- use QL\QueryList;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- class PoemContent extends Command
- {
- protected static string $defaultName = 'poem:content';
- protected static string $defaultDescription = '采集作品详情';
- protected function execute(InputInterface $input, OutputInterface $output): int
- {
- try {
- $nextPage = 1; $done = 0; $subPage = 1;
- while (is_numeric($nextPage)) {
- $output->writeln("开始" . getDateFull());
- $resp = (new \app\model\poem\PoemData)->where("is_done",0)->page($nextPage,10)->select();
- if ($resp->isEmpty()) {
- $output->writeln("没有更多任务啦!===".getDateFull());
- $nextPage = null;
- return self::SUCCESS;
- }
- $model = (new \app\model\poem\PoemContent);
- foreach ($resp as $val) {
- $output->writeln("标题:{$val['title']}==作者:{$val['author_name']}===链接地址:https://www.gushiji.cc/gushi/{$val['poem_id']}.html====".getDateFull());
- $ql = QueryList::getInstance()->get("https://www.gushiji.cc/gushi/{$val['poem_id']}.html")->rules([
- "data" => [".shicicontent","text"],
- "tags" => [".relatedCategory>ul>li>a","texts"],
- "notes" => [".shici-content","texts"],
- ])->query()->getData(function ($item,$key){
- foreach ($item['notes'] as $k=>$v){
- if ($k == 0) {
- $note = splitTransAndNote($v);
- } else {
- $note = $v;
- }
- $item['notes'][$k] = $note;
- }
- return $item;
- });
- $respData = $ql->all();
- $poemData = $model->where("poem_id",$val['poem_id'])->findOrEmpty();
- if ($poemData->isEmpty()) {
- $output->writeln("【新增】标题:{$val['title']}====".getDateFull());
- $poemData->insertGetId([
- 'poem_id' => $val['poem_id'],
- "content" => $respData['data'],
- "trans" => $respData['notes'][0]['trans']??'',
- "note" => $respData['notes'][0]['note']??'',
- "review" => $respData['notes'][1]??'',
- "background" => $respData['notes'][2]??'',
- ]);
- } else {
- $output->writeln("【更新】标题:{$val['title']}====".getDateFull());
- $poemData->save([
- "content" => $respData['data'],
- "trans" => $respData['notes'][0]['trans']??'',
- "note" => $respData['notes'][0]['note']??'',
- "review" => $respData['notes'][1]??'',
- "background" => $respData['notes'][2]??''
- ]);
- }
- (new \app\model\poem\PoemData)->where('id',$val['id'])->save(['is_done'=>1,"tags" => json_encode($respData['tags'])]);
- }
- $nextPage = $nextPage+1;
- $output->writeln("进入下一篇=={$nextPage}==".getDateFull());
- }
- } catch (\Throwable $throwable) {
- echo $throwable->getMessage()."\n";
- }
- return self::SUCCESS;
- }
- }
|