fix: a bunch of small changes in multiple bridges (#2644)

Mostly refactors.
This commit is contained in:
Dag 2022-04-12 23:37:30 +02:00 committed by GitHub
parent 5b7dd45b20
commit b6e8350596
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 81 additions and 46 deletions

View File

@ -15,7 +15,9 @@ class DanbooruBridge extends BridgeAbstract {
'type' => 'number'
),
't' => array(
'name' => 'tags'
'type' => 'text',
'name' => 'tags',
'exampleValue' => 'cosplay',
)
),
0 => array()

View File

@ -18,7 +18,7 @@ class FSecureBlogBridge extends BridgeAbstract {
),
'oldest_date' => array(
'name' => 'Oldest article date',
'exampleValue' => '-2 months',
'exampleValue' => '-6 months',
),
)
);

View File

@ -68,6 +68,7 @@ class GelbooruBridge extends BridgeAbstract {
public function collectData(){
$content = getContents($this->getFullURI());
// $content is empty string
// Most other Gelbooru-based boorus put their content in the root of
// the JSON. This check is here for Bridges that inherit from this one

View File

@ -13,6 +13,7 @@ class KhinsiderBridge extends BridgeAbstract
$html = getSimpleHTMLDOM(self::URI);
$dates = $html->find('#EchoTopic h3');
// $dates is empty
foreach ($dates as $date) {
$item = array();
$item['uri'] = self::URI;

View File

@ -17,7 +17,8 @@ class KununuBridge extends BridgeAbstract {
'Germany' => 'de',
'Switzerland' => 'ch',
'United States' => 'us'
)
),
'exampleValue' => 'de',
),
'full' => array(
'name' => 'Load full article',
@ -46,7 +47,7 @@ class KununuBridge extends BridgeAbstract {
'company' => array(
'name' => 'Company',
'required' => true,
'exampleValue' => 'kununu-us',
'exampleValue' => 'adesso',
'title' => 'Insert company name (i.e. Kununu US) or URI path (i.e. kununu-us)'
)
)
@ -72,7 +73,8 @@ class KununuBridge extends BridgeAbstract {
break;
}
return self::URI . $site . '/' . $company . '/' . $section . '?sort=update_time_desc';
$url = sprintf('%s%s/%s/%s?sort=update_time_desc', self::URI, $site, $company, $section);
return $url;
}
return parent::getURI();
@ -91,6 +93,9 @@ class KununuBridge extends BridgeAbstract {
return 'https://www.kununu.com/favicon-196x196.png';
}
/**
* All css selectors need rework
*/
public function collectData(){
$full = $this->getInput('full');

View File

@ -3,6 +3,7 @@ class LegifranceJOBridge extends BridgeAbstract {
const MAINTAINER = 'Pierre Mazière';
const NAME = 'Journal Officiel de la République Française';
// This uri returns a snippet of js. Should probably be https://www.legifrance.gouv.fr/jorf/jo/
const URI = 'https://www.legifrance.gouv.fr/affichJO.do';
const DESCRIPTION = 'Returns the laws and decrees officially registered daily in France';

View File

@ -20,6 +20,8 @@ class MsnMondeBridge extends BridgeAbstract {
$html = getSimpleHTMLDOM($this->getURI());
$limit = 0;
// TODO: fix why articles is empty
foreach($html->find('.smalla') as $article) {
if($limit < 10) {
$item = array();

View File

@ -9,7 +9,7 @@ class PillowfortBridge extends BridgeAbstract {
'name' => 'Username',
'type' => 'text',
'required' => true,
'exampleValue' => 'vaxis2',
'exampleValue' => 'SomniumAeterna',
),
'noava' => array(
'name' => 'Hide avatar',
@ -39,6 +39,29 @@ class PillowfortBridge extends BridgeAbstract {
)
));
/**
* The Pillowfort bridge.
*
* Pillowfort pages are dynamically generated from a json file
* which holds the last 20 or so posts from the given user.
* This bridge uses that json file and HTML/CSS similar
* to the Twitter bridge for formatting.
*/
public function collectData() {
$jsonSite = getContents($this->getJSONURI());
$jsonFile = json_decode($jsonSite, true);
$posts = $jsonFile['posts'];
foreach($posts as $post) {
$item = $this->getItemFromPost($post);
//empty when 'noreblogs' is checked and current post is a reblog.
if(!empty($item))
$this->items[] = $item;
}
}
public function getName() {
$name = $this -> getUsername();
if($name != '')
@ -56,7 +79,7 @@ class PillowfortBridge extends BridgeAbstract {
}
protected function getJSONURI() {
return $this -> getURI() . '/json';
return $this -> getURI() . '/json/?p=1';
}
protected function getUsername() {
@ -196,27 +219,4 @@ EOD;
return $item;
}
/**
* The Pillowfort bridge.
*
* Pillowfort pages are dynamically generated from a json file
* which holds the last 20 or so posts from the given user.
* This bridge uses that json file and HTML/CSS similar
* to the Twitter bridge for formatting.
*/
public function collectData() {
$jsonSite = getContents($this -> getJSONURI());
$jsonFile = json_decode($jsonSite, true);
$posts = $jsonFile['posts'];
foreach($posts as $post) {
$item = $this->getItemFromPost($post);
//empty when 'noreblogs' is checked and current post is a reblog.
if(!empty($item))
$this->items[] = $item;
}
}
}

View File

@ -11,7 +11,9 @@ class RobinhoodSnacksBridge extends BridgeAbstract {
{
$html = getSimpleHTMLDOM(self::URI);
foreach ($html->find('#root > div > div > div > div > div > a') as $element) {
$elements = $html->find('#__next > div > div > div > div > div > a');
foreach ($elements as $element) {
if ($element->href === 'https://snacks.robinhood.com/newsletters/page/2/') {
continue;
}

View File

@ -67,7 +67,13 @@ class TorrentGalaxyBridge extends BridgeAbstract {
$item = array();
$item['uri'] = self::URI . $identity->href;
$item['title'] = $identity->plaintext;
$item['timestamp'] = DateTime::createFromFormat('d/m/y H:i', $creadate)->format('U');
// todo: parse date strings such as '1Hr ago' etc.
$createdAt = DateTime::createFromFormat('d/m/y H:i', $creadate);
if ($createdAt) {
$item['timestamp'] = $createdAt->format('U');
}
$item['author'] = $authorid->plaintext;
$item['content'] = <<<HTML
<h1>{$identity->plaintext}</h1>

View File

@ -17,21 +17,24 @@ class ViadeoCompanyBridge extends BridgeAbstract {
));
public function collectData(){
$html = '';
$link = self::URI . 'fr/company/' . $this->getInput('c');
// Redirects to https://emploi.lefigaro.fr/recherche/entreprises
$url = sprintf('%sfr/company/%s', self::URI, $this->getInput('c'));
$html = getSimpleHTMLDOM($link);
$html = getSimpleHTMLDOM($url);
foreach($html->find('//*[@id="company-newsfeed"]/ul/li') as $element) {
// TODO: Fix broken xpath selector
$elements = $html->find('//*[@id="company-newsfeed"]/ul/li');
foreach($elements as $element) {
$title = $element->find('p', 0)->innertext;
if($title) {
$item = array();
$item['uri'] = $link;
$item['title'] = mb_substr($element->find('p', 0)->innertext, 0, 100);
$item['content'] = $element->find('p', 0)->innertext;;
$this->items[] = $item;
$i++;
if(!$title) {
continue;
}
$item = array();
$item['uri'] = $url;
$item['title'] = mb_substr($element->find('p', 0)->innertext, 0, 100);
$item['content'] = $element->find('p', 0)->innertext;;
$this->items[] = $item;
}
}
}

View File

@ -1,4 +1,5 @@
<?php
class ZenodoBridge extends BridgeAbstract {
const MAINTAINER = 'theradialactive';
const NAME = 'Zenodo';
@ -17,10 +18,21 @@ class ZenodoBridge extends BridgeAbstract {
ENT_QUOTES
)
);
foreach($element->find('p', 0)->find('span') as $authors) {
$item['author'] = $item['author'] . $authors . '; ';
$p1 = $element->find('p', 0);
if ($p1) {
foreach ($p1->find('span') as $authors) {
$item['author'] = $item['author'] . $authors . '; ';
}
}
$content = $element->find('p.hidden-xs', 0)->find('a', 0)->innertext . '<br>';
$p2 = $element->find('p.hidden-xs', 0);
if ($p2) {
$content = $p2->find('a', 0)->innertext . '<br>';
} else {
$content = 'Nope';
}
$type = '<br>Type: ' . $element->find('span.label-default', 0)->innertext;
$raw_date = $element->find('small.text-muted', 0)->innertext;