Skip to content

Commit

Permalink
fix(legifrance): emergency repair, still semi-broken (#4391)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvikan authored Jan 3, 2025
1 parent d36cd0a commit db3899f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
6 changes: 4 additions & 2 deletions bridges/DansTonChatBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ class DansTonChatBridge extends BridgeAbstract

public function collectData()
{
$html = getSimpleHTMLDOM(self::URI . 'latest.html');
$url = self::URI . 'latest.html';
$dom = getSimpleHTMLDOM($url);

foreach ($html->find('div.item') as $element) {
$items = $dom->find('div.item');
foreach ($items as $element) {
$item = [];
$item['uri'] = $element->find('a', 0)->href;
$titleContent = $element->find('h3 a', 0);
Expand Down
64 changes: 34 additions & 30 deletions bridges/LegifranceJOBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,37 @@ class LegifranceJOBridge extends BridgeAbstract
private $timestamp;
private $uri;

public function collectData()
{
$html = getSimpleHTMLDOM(self::URI);

$title = $html->find('h2.titleJO', 0);

//$this->author = trim($title->plaintext);
$uri1 = $html->find('h2.titleELI', 0);
//$uri = $uri1->plaintext;
//$this->uri = trim(substr($uri, strpos($uri, 'https')));
$this->timestamp = strtotime(substr($this->uri, strpos($this->uri, 'eli/jo/') + strlen('eli/jo/'), -5));

foreach ($html->find('h3') as $section) {
$subsections = $section->nextSibling()->find('h4');
foreach ($subsections as $subsection) {
$origins = $subsection->nextSibling()->find('h5');
foreach ($origins as $origin) {
$this->items[] = $this->extractItem($section, $subsection, $origin);
}
if (!empty($origins)) {
continue;
}
$this->items[] = $this->extractItem($section, $subsection);
}
if (!empty($subsections)) {
continue;
}
$this->items[] = $this->extractItem($section);
}
}

private function extractItem($section, $subsection = null, $origin = null)
{
$item = [];
Expand All @@ -35,7 +66,9 @@ private function extractItem($section, $subsection = null, $origin = null)
$item['content'] = '';
foreach ($data->nextSibling()->find('a') as $content) {
$text = $content->plaintext;
$href = $content->nextSibling()->getAttribute('resource');
$href = '';
//$href = $content->nextSibling()->getAttribute('resource');

$item['content'] .= '<p><a href="' . $href . '">' . $text . '</a></p>';
}
return $item;
Expand All @@ -45,33 +78,4 @@ public function getIcon()
{
return 'https://www.legifrance.gouv.fr/img/favicon.ico';
}

public function collectData()
{
$html = getSimpleHTMLDOM(self::URI)
or $this->returnServer('Unable to download ' . self::URI);

$this->author = trim($html->find('h2.titleJO', 0)->plaintext);
$uri = $html->find('h2.titleELI', 0)->plaintext;
$this->uri = trim(substr($uri, strpos($uri, 'https')));
$this->timestamp = strtotime(substr($this->uri, strpos($this->uri, 'eli/jo/') + strlen('eli/jo/'), -5));

foreach ($html->find('h3') as $section) {
$subsections = $section->nextSibling()->find('h4');
foreach ($subsections as $subsection) {
$origins = $subsection->nextSibling()->find('h5');
foreach ($origins as $origin) {
$this->items[] = $this->extractItem($section, $subsection, $origin);
}
if (!empty($origins)) {
continue;
}
$this->items[] = $this->extractItem($section, $subsection);
}
if (!empty($subsections)) {
continue;
}
$this->items[] = $this->extractItem($section);
}
}
}

0 comments on commit db3899f

Please sign in to comment.