From 9a76ce372bec0cf642c47588c07ea956854cf73e Mon Sep 17 00:00:00 2001 From: toom1996 Date: Wed, 16 Jul 2025 17:30:05 +0800 Subject: [PATCH] update --- app/Command/sitemap/Toutiao.php | 147 ++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 app/Command/sitemap/Toutiao.php diff --git a/app/Command/sitemap/Toutiao.php b/app/Command/sitemap/Toutiao.php new file mode 100644 index 0000000..4a4eda1 --- /dev/null +++ b/app/Command/sitemap/Toutiao.php @@ -0,0 +1,147 @@ +setDescription('生成头条sitemap'); + $this->addOption('platform', 'p', InputOption::VALUE_OPTIONAL, '指定的平台id.', false); + } + + public function execute(InputInterface $input, OutputInterface $output): int + { + $platform = $input->getOption('platform'); + + // 域名 + $domain = AppWebsiteConfig::find($platform)->app_domain; + + $sitemapArray = []; + + $query = AppNews::query()->select(['id', 'created_at'])->where('is_delete', 0)->get()->toArray(); + foreach ($query as $item) { +// $date = date('Y-m-d', $item['created_at']); + $sitemapArray[] = << + https://$domain/news/{$item['id']} + {$item['created_at']} + +EOF; + } + + if ($sitemapArray) { + $val = implode(PHP_EOL, $sitemapArray); + $sitemap = << + + $val + +EOF; + file_put_contents('/www/wwwroot/huoerguosifeichi/sitemap.xml', $sitemap); + } +//var_dump($links); + + + return 0; + } + + private function _getTask($brand): \Generator + { + $query = Db::table('app_brands'); + if ($brand) { + $query->where(['id' => $brand]); + } + + $query->where('id', '>', 1)->orderBy('id'); + foreach ($query->cursor() as $row) { + yield $row; + } + } + + private function _getTaskName($name): string + { + return strtolower(strtr($name, [ + '.' => '-', + ' ' => '-' + ])); + } + + public function spiderStart(): void + { + list($result, $httpCode) = $this->request($this->getBaseUrl() . '/fashion/street-style/'); + + preg_match_all('/