From 6a19c62fcf02155efaa69fc92a824055808f357d Mon Sep 17 00:00:00 2001 From: Francisco Pessano Date: Wed, 14 Jul 2021 16:24:22 -0300 Subject: [PATCH] Empezado a desarrollar la extraccion de noticias de la DB --- control-files/00_ids_done.txt | 2 +- control-files/00_news_done.txt | 2 +- index.php | 18 +++++++++++++++++ news_logic.php | 35 ++++++++++++++++++++++++---------- style.css | 2 +- 5 files changed, 46 insertions(+), 13 deletions(-) diff --git a/control-files/00_ids_done.txt b/control-files/00_ids_done.txt index 301160a..e440e5c 100755 --- a/control-files/00_ids_done.txt +++ b/control-files/00_ids_done.txt @@ -1 +1 @@ -8 \ No newline at end of file +3 \ No newline at end of file diff --git a/control-files/00_news_done.txt b/control-files/00_news_done.txt index 3a4c169..3a86d75 100755 --- a/control-files/00_news_done.txt +++ b/control-files/00_news_done.txt @@ -1 +1 @@ -/news/6.html./news/7.html./news/8.html \ No newline at end of file +./news/1.html ./news/2.html ./news/3.html \ No newline at end of file diff --git a/index.php b/index.php index ddac30c..57ae4d3 100755 --- a/index.php +++ b/index.php @@ -21,6 +21,24 @@ require 'news_logic.php'; check_news(); + + $news_per_page = 10; + + $result = bring_the_news_back_home(1, $news_per_page); + + foreach ($result as $news ) { + $title = $news[0]; + $frist_p = $news[1]; + $icon = $news[2]; + + echo "
+ +
+

$title

+

$frist_p

+
+
"; + } ?> diff --git a/news_logic.php b/news_logic.php index 7397095..49fa39d 100755 --- a/news_logic.php +++ b/news_logic.php @@ -7,15 +7,12 @@ function check_news() { $news = glob('./news/*'); foreach ($news as $news_unique) { - if ($news_unique !== './control-files/00_news_done.txt' && $news_unique !== './control-files/00_ids_done.txt' ){ + $news_done = file_get_contents('./control-files/00_news_done.txt'); - $news_done = file_get_contents('./control-files/00_news_done.txt'); - - if (!strstr($news_done, $news_unique)) { - $page = know_page($news_unique); - $author = know_author($page, $news_unique); - create_entry_in_DB($news_unique, $page, $author); //! HACER FUNCION - } + if (!strstr($news_done, $news_unique)) { + $page = know_page($news_unique); + $author = know_author($page, $news_unique); + create_entry_in_DB($news_unique, $page, $author); } } } @@ -64,8 +61,9 @@ function create_entry_in_DB($news_unique, $page, $author) { switch ($page) { case 'Xataka': - $title = get_string_between($content, '

', '

'); - $pre_icon = get_string_between($content, '
', '
'); + $pre_title = get_string_between($content, '

', '

'); + $title = get_string_between($pre_title, '', ''); + $pre_icon = get_string_between($content, ', '); $icon = get_string_between($pre_icon, 'src=', ' '); $inner_HTML = get_string_between($content, '
', '
') . ''; $frist_p = strip_tags(get_string_between($inner_HTML, '

', '

')); @@ -96,5 +94,22 @@ function create_entry_in_DB($news_unique, $page, $author) { } +function bring_the_news_back_home($actual_page, $news_per_page) { + require './mySQLconnect.php'; + + $frist_calc = $actual_page * $news_per_page; + $second_calc = ($actual_page * $news_per_page) - $news_per_page; + + $prepared_query = $mySQLconnect -> prepare("select title, frist_paragraph, icon_route 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)); + + $prepared_query -> execute(); + + $return = $prepared_query -> fetchAll(); + + return $return; +} ?> \ No newline at end of file diff --git a/style.css b/style.css index 4b9792c..b4c61ff 100755 --- a/style.css +++ b/style.css @@ -90,7 +90,7 @@ header { .card h3 { font-family: 'Times New Roman', Times, serif; font-weight: lighter; - font-size: 12pt; + font-size: 12.5pt; color: #999999; }