rss-bridge/bridges/PresidenciaPTBridge.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

89 lines
2.8 KiB
PHP
Raw Normal View History

2021-03-17 19:30:47 +03:00
<?php
class PresidenciaPTBridge extends BridgeAbstract
{
2021-03-17 19:30:47 +03:00
const NAME = 'Presidência da República Portuguesa';
const URI = 'https://www.presidencia.pt';
const DESCRIPTION = 'Presidência da República Portuguesa';
2021-03-17 19:30:47 +03:00
const MAINTAINER = 'somini';
const PARAMETERS = [
'Section' => [
'/atualidade/noticias' => [
'name' => 'Notícias',
'type' => 'checkbox',
'defaultValue' => 'checked',
],
'/atualidade/mensagens' => [
'name' => 'Mensagens',
'type' => 'checkbox',
'defaultValue' => 'checked',
],
'/atualidade/atividade-legislativa' => [
'name' => 'Atividade Legislativa',
'type' => 'checkbox',
'defaultValue' => 'checked',
],
'/atualidade/notas-informativas' => [
'name' => 'Notas Informativas',
'type' => 'checkbox',
2021-03-17 19:30:47 +03:00
'defaultValue' => 'checked',
]
]
2021-03-17 19:30:47 +03:00
];
const PT_MONTH_NAMES = [
2021-03-17 19:30:47 +03:00
'janeiro',
'fevereiro',
2021-03-17 19:30:47 +03:00
'março',
'abril',
'maio',
'junho',
'julho',
'agosto',
'setembro',
'outubro',
'novembro',
'dezembro'];
2021-03-17 19:30:47 +03:00
public function getIcon()
{
return 'https://www.presidencia.pt/Theme/favicon/apple-touch-icon.png';
}
2021-03-17 19:30:47 +03:00
public function collectData()
{
2024-01-25 15:03:00 +03:00
$contexts = $this->getParameters();
foreach (array_keys($contexts['Section']) as $k) {
Debug::log('Key: ' . var_export($k, true));
if ($this->getInput($k)) {
$html = getSimpleHTMLDOMCached($this->getURI() . $k);
2021-03-17 19:30:47 +03:00
foreach ($html->find('#atualidade-list article.card-block') as $element) {
$item = [];
2021-03-17 19:30:47 +03:00
$link = $element->find('a', 0);
$etitle = $element->find('.article-title', 0);
$edts = $element->find('.date', 0);
$edt = $edts->innertext;
2021-03-17 19:30:47 +03:00
$item['title'] = strip_tags($etitle->innertext);
$item['uri'] = self::URI . $link->href;
$item['description'] = $element;
$item['timestamp'] = str_ireplace(
array_map(function ($name) {
return ' de ' . $name . ' de ';
}, self::PT_MONTH_NAMES),
array_map(function ($num) {
return sprintf('-%02d-', $num);
}, range(1, count(self::PT_MONTH_NAMES))),
$edt
);
$this->items[] = $item;
2021-03-17 19:30:47 +03:00
}
}
}
}
2021-03-17 19:30:47 +03:00
}