mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-03-14 20:21:14 +03:00
feat: new bridge pokemonnews (#3042)
* feat: new bridge pokemonnews fix #3040 * fix
This commit is contained in:
parent
11220ef373
commit
55cc74c816
1 changed files with 44 additions and 0 deletions
44
bridges/PokemonNewsBridge.php
Normal file
44
bridges/PokemonNewsBridge.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
final class PokemonNewsBridge extends BridgeAbstract
|
||||
{
|
||||
const NAME = 'Pokemon.com news';
|
||||
const URI = 'https://www.pokemon.com/us/pokemon-news';
|
||||
const DESCRIPTION = 'Fetches the latest news from pokemon.com';
|
||||
const MAINTAINER = 'dvikan';
|
||||
|
||||
public function collectData()
|
||||
{
|
||||
// todo: parse json api instead: https://www.pokemon.com/api/1/us/news/get-news.json
|
||||
$url = 'https://www.pokemon.com/us/pokemon-news';
|
||||
$dom = getSimpleHTMLDOM($url);
|
||||
|
||||
foreach ($dom->find('.news-list ul li') as $item) {
|
||||
$title = $item->find('h3', 0)->plaintext;
|
||||
$description = $item->find('p.hidden-mobile', 0);
|
||||
$dateString = $item->find('p.date', 0)->plaintext;
|
||||
// e.g. September 15, 2022
|
||||
$createdAt = date_create_from_format('F d, Y', $dateString);
|
||||
// todo:
|
||||
$tagsString = $item->find('p.tags', 0)->plaintext;
|
||||
$path = $item->find('a', 0)->href;
|
||||
$imagePath = $item->find('img', 0)->src;
|
||||
$tags = explode('&', $tagsString);
|
||||
$tags = array_map('trim', $tags);
|
||||
|
||||
$this->items[] = [
|
||||
'title' => $title,
|
||||
'uri' => sprintf('https://www.pokemon.com%s', $path),
|
||||
'timestamp' => $createdAt ? $createdAt->getTimestamp() : time(),
|
||||
'categories' => $tags,
|
||||
'content' => sprintf(
|
||||
'<img src="https://pokemon.com%s"><br><br>%s',
|
||||
$imagePath,
|
||||
$description ? $description->plaintext : ''
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue