Soporte para Infobae añadido

This commit is contained in:
2021-07-16 21:09:07 -03:00
parent 00ff3b2ad9
commit e60588e577
8 changed files with 152 additions and 4 deletions

View File

@@ -1 +1 @@
7
8

View File

@@ -1 +1 @@
./news/1.html ./news/2.html ./news/3.html ./news/4.html ./news/5.html ./news/6.html ./news/7.html
./news/1.html ./news/2.html ./news/3.html ./news/4.html ./news/5.html ./news/6.html ./news/7.html ./news/8.html

View File

@@ -40,6 +40,7 @@
$title = $news[1];
$frist_p = $news[2];
$icon = $news[3];
$source = $news[4];
echo
"<a href='news.php?id=$id' class='card-link'>
@@ -48,6 +49,7 @@
<div class='text'>
<h2>$title</h2>
<h3>$frist_p</h3>
<div class='source'>$source</div>
</div>
</div>
</a>";

View File

@@ -1,5 +1,7 @@
<?php
use JetBrains\PhpStorm\Internal\ReturnTypeContract;
error_reporting(~0);
ini_set('display_errors', 1);
@@ -26,7 +28,11 @@ function know_page($news_unique) {
case $news_unique === './news/genbeta.html' || $news_unique === './news/Genbeta.html':
return 'Genbeta';
break;
case $news_unique === './news/infobae.html' || $news_unique === './news/Infobae.html':
return 'Infobae';
break;
default:
return 0;
break;
@@ -49,6 +55,10 @@ function know_author($page, $news_unique) {
return str_replace('>', '', $second_cut);
break;
case $page === 'Infobae':
return $author = get_string_between($content, ',t.authors="', '",');
break;
default:
return 0;
break;
@@ -87,12 +97,24 @@ function create_entry_in_DB($news_unique, $page, $author) {
$inner_HTML = get_string_between($content, '<div class="article-content">', '<div class="article-content-outer">') . '<script id="script-estructurator" src="./scripts/genbeta.js"></script>';
$frist_p = strip_tags(get_string_between($inner_HTML, '<p>', '</p>'));
break;
case $page === 'Infobae':
$title = get_string_between($content, '<html lang="es"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>', '- Infobae</title>');
$pre_icon = get_string_between($content, '<div class="visual__image ">', '</div>');
$icon = get_string_between($pre_icon, '992w,', ' 1200w" ');
$inner_HTML = get_string_between($content, '<section class="article-section page-container">', '</section>') . '<script id="script-estructurador" src="./scripts/infobae.js"></script>';
$frist_p = get_string_between($content, '<meta property="og:description" content="', '">');
break;
default:
echo 0;
return 0;
break;
}
$title;
$icon;
$inner_HTML;
$frist_p;
$insert_news = $mySQLconnect -> prepare('insert into noticias (title, content, icon_route, page_source, author, frist_paragraph) values (?, ?, ?, ?, ?, ?)');
@@ -119,7 +141,7 @@ function bring_the_news_back_home($actual_page, $news_per_page) {
$frist_calc = $actual_page * $news_per_page;
$second_calc = ($actual_page * $news_per_page) - $news_per_page;
$prepared_query = $mySQLconnect -> prepare("select id, title, frist_paragraph, icon_route from noticias where id < ? and id > ?");
$prepared_query = $mySQLconnect -> prepare("select id, title, frist_paragraph, icon_route, page_source from noticias where id < ? and id > ?");
$prepared_query -> bindParam(1, $frist_calc, PDO::PARAM_INT);
$prepared_query -> bindParam(2, $second_calc, PDO::PARAM_INT);
//$prepared_query -> execute(array($actual_page * 10, $actual_page * 10 - 10));

0
scripts/genbeta.js Normal file → Executable file
View File

87
scripts/infobae.js Executable file
View File

@@ -0,0 +1,87 @@
//todo - Informacion de infobae
title = document.getElementsByClassName('article-headline')[0];
console.log(title);
sub_title = document.getElementsByClassName('article-subheadline')[0];
console.log(sub_title);
content = document.getElementsByClassName('nd-body-article')[0];
console.log(content);
trash = [document.getElementsByClassName('infogram-embed')[0]];
console.log(trash);
paragraphs = document.querySelectorAll('.paragraph, .visual__image');
console.log(paragraphs);
infobae = document.getElementsByTagName('article')[0];
//todo - Estructura del sitio web cliente
all = document.getElementsByClassName('all')[0];
console.log(all);
//todo - Purificacion de la informacion
for (let i = 0; i < paragraphs.length; i++) {
if (paragraphs[i].innerHTML == "<b>SEGUIR LEYENDO:</b>" || paragraphs[i].innerHTML == "<b>SEGUIR LEYENDO</b>" || paragraphs[i].innerHTML == "<br>") {
console.log("AAAAA");
trash.push(paragraphs[i])
}
}
title.innerHTML = ''
for (let i = 0; i < trash.length; i++) {
if (trash[i] !== undefined){
trash[i].innerHTML = ''
trash[i].remove();
}
}
//todo - Copiar e insertar informacion en el sitio web cliente
//! TITULO
all.appendChild(title);
frist_p = document.createElement("P")
frist_p.innerText = sub_title.innerText
//! PARRAFOS
paragraphsFragment = document.createDocumentFragment();
paragraphsFragment.appendChild(frist_p)
for (let i = 0; i < paragraphs.length; i++) {
if (paragraphs[i].className == "visual__image ") {
console.log("AAAA");
paragraphs[i].children[0].style.height = "auto"
paragraphs[i].children[0].style.width = "100%"
}
console.log(paragraphs[i]);
paragraphsFragment.appendChild(paragraphs[i])
}
article = document.createElement('article')
article.appendChild(paragraphsFragment)
all.appendChild(article)
//todo - Eliminar informacion de infobae
infobae.remove()
//todo - Eliminar el script
script = document.getElementById('script-estructurator');
script.remove()

View File

@@ -80,6 +80,8 @@ header {
margin-right: 2vw;
width: calc(74vw - 150px - 6vw);
margin-bottom: 2vh;
display: flex;
flex-direction: column;
}
.card h2 {
@@ -113,3 +115,7 @@ header {
color: #797979;
}
.card .source {
align-self: flex-end;
flex-grow: 1;
}

31
test-page.php Executable file
View File

@@ -0,0 +1,31 @@
<link rel="stylesheet" href="news.css">
<body>
<header>
<a href="index.php" class="name">
<img class="logo" src="./img/logo.svg">
<h1>AllNews.com</h1>
</a>
</header>
<div class="all">
<article>
<?php
require 'news_logic.php';
check_news();
?>
</article>
</div>
<div class="source">
Autor: <b><?php echo $author;?></b> | Pagina fuente: <b><?php echo $page_source;?></b>
</div>
</body>