-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,40 @@ | ||
<?php | ||
class MsnMondeBridge extends BridgeAbstract { | ||
class MsnMondeBridge extends FeedExpander { | ||
|
||
const MAINTAINER = 'kranack'; | ||
const NAME = 'MSN Actu Monde'; | ||
const URI = 'http://www.msn.com/'; | ||
const DESCRIPTION = 'Returns the 10 newest posts from MSN Actualités (full text)'; | ||
const URI = 'https://www.msn.com/fr-fr/actualite'; | ||
const FEED_URL = 'https://rss.msn.com/fr-fr'; | ||
const JSON_URL = 'https://assets.msn.com/content/view/v2/Detail/fr-fr/'; | ||
const LIMIT = 10; | ||
|
||
public function getURI(){ | ||
return self::URI . 'fr-fr/actualite/monde'; | ||
public function getName() { | ||
return 'MSN Actualités'; | ||
} | ||
|
||
private function msnMondeExtractContent($url, &$item){ | ||
$html2 = getSimpleHTMLDOM($url); | ||
$item['content'] = $html2->find('#content', 0)->find('article', 0)->find('section', 0)->plaintext; | ||
$item['timestamp'] = strtotime($html2->find('.authorinfo-txt', 0)->find('time', 0)->datetime); | ||
public function getURI() { | ||
return self::URI; | ||
} | ||
|
||
public function collectData(){ | ||
$html = getSimpleHTMLDOM($this->getURI()); | ||
public function collectData() { | ||
$this->collectExpandableDatas(self::FEED_URL, self::LIMIT); | ||
} | ||
|
||
$limit = 0; | ||
protected function parseItem($newsItem) { | ||
$item = parent::parseItem($newsItem); | ||
if (!preg_match('#fr-fr/actualite.*/ar-(?<id>[\w]*)\?#', $item['uri'], $matches)) { | ||
return; | ||
} | ||
|
||
// TODO: fix why articles is empty | ||
foreach($html->find('.smalla') as $article) { | ||
if($limit < 10) { | ||
$item = array(); | ||
$item['title'] = utf8_decode($article->find('h4', 0)->innertext); | ||
$item['uri'] = self::URI . utf8_decode($article->find('a', 0)->href); | ||
$this->msnMondeExtractContent($item['uri'], $item); | ||
$this->items[] = $item; | ||
$limit++; | ||
} | ||
$json = json_decode(getContents(self::JSON_URL . $matches['id']), true); | ||
$item['content'] = $json['body']; | ||
if (!empty($json['authors'])) | ||
$item['author'] = reset($json['authors'])['name']; | ||
$item['timestamp'] = $json['createdDateTime']; | ||
foreach($json['tags'] as $tag) { | ||
$item['categories'][] = $tag['label']; | ||
} | ||
return $item; | ||
} | ||
} |