eckendoerffer commited on
Commit
eaee53a
1 Parent(s): e180776

Upload 10 files

Browse files
extract_news/1_extract_rss.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * RSS Article URL Extractor
5
+ *
6
+ * This script is designed to fetch and extract article URLs from the RSS feeds of various French media outlets.
7
+ * The sources of these RSS feeds are stored in the `base_media` table of the database.
8
+ * For each source, the script retrieves the RSS content, processes each entry, and stores the article URLs
9
+ * into the database for further processing or analysis.
10
+ *
11
+ * @author Guillaume Eckendoerffer
12
+ * @date 07-09-2023
13
+ */
14
+
15
+
16
+ // Include the database functions
17
+ include( "functions_mysqli.php" );
18
+
19
+ // Initialize global variables
20
+ $last = date("U");
21
+ $path = $_SERVER['DOCUMENT_ROOT'];
22
+
23
+ /**
24
+ * Fetches the latest URL from the database.
25
+ *
26
+ * @param mysqli $mysqli The mysqli connection object.
27
+ * @return array Associative array containing the ID, URL, and the last update time.
28
+ */
29
+ function fetchLatestURL( $mysqli ) {
30
+ $result = mysqli_query( $mysqli, "SELECT `id`, `url`, `last` FROM `base_media` ORDER By `last` ASC LIMIT 1" );
31
+ return mysqli_fetch_assoc( $result );
32
+ }
33
+
34
+ /**
35
+ * Updates the last fetched timestamp for the given source.
36
+ *
37
+ * @param mysqli $mysqli The mysqli connection object.
38
+ * @param int $id_source The ID of the source to update.
39
+ * @param int $last The new timestamp.
40
+ */
41
+ function updateLastFetched( $mysqli, $id_source, $last ) {
42
+ mysqli_query( $mysqli, "UPDATE `base_media` SET `last`='$last' WHERE `id`='$id_source' LIMIT 1" );
43
+ }
44
+
45
+ /**
46
+ * Fetches the content from a given URL.
47
+ *
48
+ * @param string $url The URL to fetch.
49
+ * @return string The content of the fetched URL.
50
+ */
51
+ function fetchURLContent( $url) {
52
+ $data = file_get_contents( trim( $url ) );
53
+ return $data;
54
+ }
55
+
56
+ /**
57
+ * Saves the given content to a file.
58
+ *
59
+ * @param string $path The path where the content should be saved.
60
+ * @param string $data The content to save.
61
+ */
62
+ function saveToFile( $path, $data ) {
63
+ $file = fopen( $path, "w" );
64
+ fwrite( $file, $data );
65
+ fclose( $file );
66
+ }
67
+
68
+ /**
69
+ * Processes the fetched RSS content and updates the database accordingly.
70
+ *
71
+ * @param mysqli $mysqli The mysqli connection object.
72
+ * @param string $content The RSS content.
73
+ * @param int $id_source The ID of the source.
74
+ */
75
+ function processRSSContent( $mysqli, $content, $id_source ) {
76
+ $a = new SimpleXMLElement( $content );
77
+ $nb = 0;
78
+
79
+ // First attempt: Process each item in the channel
80
+ foreach ( $a->channel->item as $entry ) {
81
+ $media = $entry->children( 'media', TRUE );
82
+ $attributes = $media->content->attributes();
83
+ $src = $attributes['url'];
84
+ $url = trim( $entry->link );
85
+ $url = str_replace(strstr( $url, "#"), "", $url );
86
+ $url = str_replace(strstr( $url, "?utm"), "", $url );
87
+ $url = str_replace(strstr( $url, "?xtor"), "", $url );
88
+ $key = md5( $url );
89
+
90
+ $txt = addslashes( strip_tags( html_entity_decode( $entry->description ) ) );
91
+ $title = addslashes( strip_tags( html_entity_decode( $entry->title ) ) );
92
+ $nb++;
93
+
94
+ $nb_base = mysqli_return_number( $mysqli, "SELECT `id` FROM `base_news` WHERE `key_media`='$key' OR `url` LIKE '$url%' LIMIT 1" );
95
+
96
+ if ( trim( $url ) != '' && trim( $title ) != '' && $nb_base == 0 ) {
97
+ mysqli_query( $mysqli, "INSERT INTO `base_news` (`id`, `key_media`, `media`, `url`, `link`, `step`) VALUES (NULL, '$key', '$id_source', '$url', '0', '0');" );
98
+ $id_inserted = $mysqli->insert_id;
99
+ mysqli_query( $mysqli, "UPDATE `base_news` SET `title`='$title' WHERE `id`='$id_inserted' LIMIT 1" );
100
+ mysqli_query( $mysqli, "UPDATE `base_news` SET `txt_clean`='$txt' WHERE `id`='$id_inserted' LIMIT 1" );
101
+ }
102
+ }
103
+
104
+ // Second attempt: If no entries were processed in the first attempt, process the top-level entries
105
+ if ( !$nb ) {
106
+ foreach ( $a as $entry ) {
107
+ $url = $entry->loc;
108
+ $url = str_replace( strstr( $url, "#" ), "", $url );
109
+ $url = str_replace(strstr( $url, "?utm"), "", $url );
110
+ $key = md5( $url );
111
+ $nb++;
112
+ $nb_base = mysqli_return_number( $mysqli, "SELECT `id` FROM `base_news` WHERE `key_media`='$key' OR `url` LIKE '$url%' LIMIT 1" );
113
+
114
+ if ( trim( $url ) != '' && $nb_base == 0 ) {
115
+ mysqli_query( $mysqli, "INSERT INTO `base_news` (`id`, `key_media`, `media`, `url`, `link`, `step`) VALUES (NULL, '$key', '$id_source', '$url', '0', '0');" );
116
+
117
+ }
118
+ }
119
+ }
120
+
121
+ $nb_base_news = mysqli_return_number( $mysqli, "SELECT `id` FROM `base_news` WHERE `media` = '$id_source'" );
122
+ mysqli_query( $mysqli, "UPDATE `base_media` SET `nb`='$nb_base_news' WHERE `id`='$id_source' LIMIT 1" );
123
+ }
124
+
125
+
126
+ // Main script execution
127
+ $record = fetchLatestURL( $mysqli );
128
+ $id_source = $record['id'];
129
+ $url = trim( $record['url'] );
130
+ $last_update = $record['last'];
131
+
132
+ echo "$id_source # $url";
133
+
134
+ // Exit if the last update is too recent < 1h
135
+ if ( $last_update + 3600 > $last ) {
136
+ exit;
137
+ }
138
+
139
+ updateLastFetched( $mysqli, $id_source, $last );
140
+ $data = fetchURLContent( $url );
141
+ if( trim( $data )!='' ){
142
+ saveToFile( $path . "/sources/rss/" . $id_source . ".txt", $data );
143
+ processRSSContent( $mysqli, $data, $id_source );
144
+ }
145
+
146
+ echo "<script type=\"text/javascript\">location.href='" . $_SERVER ['REQUEST_URI'] . "';</script>";
147
+
148
+ ?>
149
+
extract_news/2_extract_news.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * News Article Source Fetcher
5
+ *
6
+ * This script is designed to extract the content of news articles from various French media sources.
7
+ * The URLs of these articles are retrieved from the `base_news` table, where articles marked with
8
+ * a `step` value of '0' are pending extraction.
9
+ *
10
+ * Once extracted, the content of each article is saved locally for further processing. This separation
11
+ * of content fetching and processing is intentional to optimize resource management.
12
+ *
13
+ * The script operates in batches, processing a defined number of entries (`NB_BY_STEP`) at a time.
14
+ * After extraction, the `step` value of the processed articles is updated to '1' to indicate completion.
15
+ *
16
+ * For performance monitoring, the script outputs the processed article IDs, URLs, and calculates the average
17
+ * processing time per article.
18
+ *
19
+ * @author Guillaume Eckendoerffer
20
+ * @date 07-09-2023
21
+ */
22
+
23
+
24
+ // Include the database functions
25
+ include( "functions_mysqli.php" );
26
+
27
+ // Initialize global variables
28
+ const NB_BY_STEP = 20; // nb per steep
29
+ $last = date( "U" );
30
+ $path = $_SERVER['DOCUMENT_ROOT'];
31
+
32
+ // Capture the start time for performance monitoring
33
+ $time_start = microtime( true );
34
+
35
+ // Fetch a batch of unprocessed news entries
36
+ $return ='';
37
+ $result = mysqli_query( $mysqli, "SELECT `id`, `url` FROM `base_news` WHERE `step`='0' ORDER BY RAND() LIMIT " . NB_BY_STEP );
38
+ while ( $row = mysqli_fetch_assoc( $result ) ) {
39
+
40
+ $id_source = $row["id"];
41
+ $url = trim( $row["url"] );
42
+ $time_start_item = microtime( true );
43
+
44
+ // Mark the news entry as being processed
45
+ mysqli_query( $mysqli, "UPDATE `base_news` SET `step`='1' WHERE `id`='$id_source' LIMIT 1" );
46
+
47
+ // Fetch the content of the news URL
48
+ $data = file_get_contents( trim( $url ) );
49
+
50
+ // Save the fetched data to a local file
51
+ $inF = fopen( "$path/sources/html_news/$id_source.txt", "w" );
52
+ fwrite( $inF, $data );
53
+ fclose( $inF );
54
+ $time_item = number_format( ( microtime( true ) - $time_start_item ) , 3, ',', '' ) . 's';
55
+
56
+ // Output the ID and URL for monitoring purposes
57
+ $return .= "($id_source) [$time_item] $url <br />";
58
+ }
59
+
60
+ // Fetch the count of news entries that haven't been processed
61
+ $nb_base = mysqli_return_number( $mysqli, "SELECT `id` FROM `base_news` WHERE `step`='0'" );
62
+
63
+ // Calculate and display the processing time
64
+ $time = number_format( ( ( microtime( true ) - $time_start ) / NB_BY_STEP ), 3, ',', '' ) .'s/item';
65
+ echo "<head><title>Rem: $nb_base - $time</title></head> $return";
66
+
67
+ // If no more entries are found, exit, else move to the next processing step
68
+ if ( !isset( $id_source ) ) exit;
69
+
70
+ echo "<script type=\"text/javascript\">location.href='" . $_SERVER ['REQUEST_URI'] . "';</script>";
71
+
72
+ ?>
73
+
extract_news/3_extract_news_txt.php ADDED
@@ -0,0 +1,386 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * News Article Text Extractor
5
+ *
6
+ * This script extracts the text from locally-stored news articles. The main goal is
7
+ * to retrieve clean text with minimal external elements, such as user menus, article lists,
8
+ * and advertisements.
9
+ *
10
+ * To use this script, you must have electrolinux/phpquery installed. Install it using Composer with
11
+ * the command: composer require electrolinux/phpquery.
12
+ *
13
+ * After completing this step, you can use the Python script located at /dataset/2_cleaning_txt.py
14
+ * to standardize the text for your dataset.
15
+ *
16
+ * Debugging:
17
+ * - Enable debugging by setting the `$debug` variable to 1. This will display the hexadecimal
18
+ * code for each character in the final version before being saved in /txt_news/. Additionally,
19
+ * it will show the full HTML version or the complete HTML source if there's no output.
20
+ * - GET variables:
21
+ * - `?id=`: Use this integer value to display a specific news article. This corresponds
22
+ * to the ID in the `base_news` table.
23
+ * - `?media=`: Use this integer value to display a specific media. This corresponds
24
+ * to the ID in the `base_media` table.
25
+ *
26
+ * Note:
27
+ * RSS feed links for media sources, as well as the HTML structure of media pages, tend to change
28
+ * and evolve regularly. It's crucial to regularly check the output per media source and adjust
29
+ * the parsing process to ensure high-quality text extraction and to address potential changes
30
+ * in RSS feed URLs.
31
+ *
32
+ * @author Guillaume Eckendoerffer
33
+ * @date 08-09-2023
34
+ */
35
+
36
+
37
+ $debug = 0;
38
+ $redirect_enabled = 1;
39
+ $time_start = microtime(true);
40
+
41
+ // composer require electrolinux/phpquery
42
+ require 'vendor/autoload.php';
43
+
44
+ // Include the database functions
45
+ include( "functions_mysqli.php" );
46
+
47
+ // Initialize global variables
48
+ $last = date( "U" );
49
+ $path = $_SERVER ['DOCUMENT_ROOT'];
50
+
51
+ /**
52
+ * Cleans the input text by replacing specific characters and filtering out unwanted Unicode categories.
53
+ *
54
+ * @param string $text The original text to be cleaned.
55
+ * @return string The cleaned text with specific replacements and filtered characters.
56
+ *
57
+ * @example
58
+ * clean_text("Hello`World!"); // Returns "Hello'World!"
59
+ */
60
+ function clean_text( $text ) {
61
+ $text = str_replace( chr( 8217 ), "'", $text );
62
+ $text = str_replace( "`", "'", $text );
63
+ $text = str_replace( "’", "'", $text );
64
+ $dict_char = str_split( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/*-+.$*ù^£–—“”—" .
65
+ "µ%¨!:;,?./§&é\"'(è_çàâ)=°ç[{#}]¤~²ôûîïäëêíáã•©®€¢¥ƒÁÂÀÅÃäÄæÇÉÊÈËÍîÎñÑÓÔóÒøØõÕö" .
66
+ "ÖœŒšŠßðÐþÞÚúûÛùÙüÜýÝÿŸαβγδεζηθικλμνξοπρστυφχψωΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ×÷" .
67
+ "±∓≠<>≤≥≈∝∞∫∑∈∉⊆⊇⊂⊃∪∩∧∨¬∀∃π×⨯⊗→←↑↓↔ ϒϖϑℵ⟩⟨⋅⊗⊄≅∗∉∅⇓⇑⇐↵ℜℑ℘⊕⊥∼∴∪∨∧∠∝" .
68
+ "∋∈∇∃∀⇔⇒∩¬∞√∑∏∂″′ªº³²¹¾½¼‰¶‡†¿§«»@" );
69
+
70
+ for ( $i = 0; $i < strlen( $text ); $i++ ) {
71
+ $char = $text[$i];
72
+ if ( !in_array( $char, $dict_char ) ) {
73
+ $text = str_replace( $char, ' ', $text );
74
+ }
75
+ }
76
+
77
+ return $text;
78
+ }
79
+
80
+ // Search for the source code of the next record to process
81
+ if( isset( $_GET["id"] ) AND is_numeric( $_GET["id"] ) ) $req="`id`='" . $_GET["id"] . "'"; else $req="`step`='1' ORDER By `id` ";
82
+ if( isset( $_GET["media"] ) AND is_numeric( $_GET["media"] ) ) $req="`media`='" . $_GET["media"] . "' ORDER By Rand() ";
83
+ $result = mysqli_query( $mysqli, "SELECT `id`, `url`, `title`, `txt_clean` FROM `base_news` WHERE $req LIMIT 1" );
84
+ while ( $row = mysqli_fetch_assoc( $result ) ) {
85
+ $id_source = $row["id"];
86
+ $next = $id_source + 1;
87
+ $url = trim( $row["url"] );
88
+ $title = trim( html_entity_decode( $row["title"] ) );
89
+ $txt_clean = trim( $row["txt_clean"] );
90
+ }
91
+ if( !isset( $id_source ) ) exit;
92
+ mysqli_query( $mysqli, "UPDATE `base_news` SET `step`='2' WHERE `id`='$id_source' LIMIT 1" );
93
+
94
+ $htmlContent = '';
95
+ $file_path = "$path/sources/html_news/$id_source.txt";
96
+ if ( file_exists( $file_path ) ) $htmlContent = implode ( '', file ( $file_path ) );
97
+ if( substr_count( $url, '/replay' ) ) $htmlContent ='';
98
+
99
+ // utf8
100
+ $current_encoding = mb_detect_encoding( $htmlContent, 'auto' );
101
+ try {
102
+ $htmlContent = ($current_encoding == 'UTF-8') ? $htmlContent : mb_convert_encoding($htmlContent, 'UTF-8', $current_encoding);
103
+ } catch (ValueError $e) {
104
+ if( $redirect_enabled )
105
+ echo "<script type=\"text/javascript\">location.href='" . str_replace( strstr( $_SERVER ['REQUEST_URI'], '?' ), "", $_SERVER ['REQUEST_URI'] ) . "?id=$next';</script>";
106
+ else
107
+ echo "Error: mb_convert_encoding()";
108
+ exit;
109
+ }
110
+
111
+ $doc = \phpQuery::newDocument( $htmlContent );
112
+
113
+ // Extracting the title
114
+ if( trim( $title )=='' ){
115
+ $title = html_entity_decode( trim( pq('h1')->text() ) );
116
+ mysqli_query( $mysqli, "UPDATE `base_news` SET `title`='" . addslashes( $title ) . "' WHERE `id`='$id_source' LIMIT 1" );
117
+ }
118
+
119
+ // Extracting the description
120
+ if( trim( $txt_clean )=='' ){
121
+ $description = pq('meta[name="description"]')->attr('content');
122
+ if( trim( $description )=='' ){
123
+
124
+ $description = pq('meta[name="og:description"]')->attr('content');
125
+ }
126
+ if( trim( $description )!='' ){
127
+
128
+ $txt_clean = html_entity_decode( trim( $description ) );
129
+ $txt_clean = preg_replace( '/\s{2,}/', ' ', $txt_clean );
130
+ }
131
+ }
132
+
133
+ // Extracting the text from source code
134
+ $content ='';
135
+ $html ='';
136
+ // Extracting the text from <article> tag
137
+ $color ='#008000';
138
+ if( !substr_count( $url, ".rtbf.be" ) ) {
139
+ foreach ( pq( 'article p' ) as $p ) {
140
+
141
+ $html .= " " . trim( pq( $p )->html() ) . " ";
142
+ if( substr_count( $url, ".futura-sciences.com" ) ) pq($p)->find('a')->remove();
143
+ $content .= " " . trim( html_entity_decode( pq( $p )->text() ) ) . " ";
144
+ }
145
+ }
146
+
147
+ // Extracting from <p> tags after <h1>
148
+ if( trim( $content )=='' ){
149
+ $start = pq('h1:first');
150
+ $nextElements = pq($start)->nextAll();
151
+ foreach ($nextElements as $element) {
152
+ if (pq($element)->is('p')) {
153
+ $start = trim(html_entity_decode(pq($element)->text()));
154
+ }
155
+ }
156
+ foreach ( pq( 'p' ) as $p ) {
157
+ $content .= " " . trim( html_entity_decode( pq( $p )->text() ) ) . " ";
158
+ }
159
+ if( trim( $start )!='' ) $content = strstr( $content, $start );
160
+
161
+ $color ='#000080';
162
+ }
163
+
164
+ // Extracting from <p> tags
165
+ if( trim( $content )=='' ){
166
+
167
+ foreach ( pq( 'p' ) as $p ) {
168
+ $content .= " " . trim( html_entity_decode( pq( $p )->text() ) ) ;
169
+ }
170
+ $color ='#888';
171
+ }
172
+
173
+ // Adding a space after punctuation and various deletions
174
+ $content = str_replace(array("\r", "\n"), ' ', $content);
175
+ $remove = [
176
+ '?',
177
+ '!',
178
+ ";",
179
+ "!",
180
+ "»",
181
+ "]",];
182
+ foreach ( $remove as $phrase ) {
183
+ $content = str_replace( $phrase, $phrase . ' ', $content );
184
+ }
185
+ $content = str_replace( html_entity_decode('&nbsp;'), " ", $content ); // Standardizing spaces
186
+ $content = preg_replace( '/\s{2,}/', ' ', $content ); // one space, no more
187
+ $pattern = '/À lire aussi.{1,200}?»/';
188
+ $content = preg_replace($pattern, ' ', $content);
189
+ $pattern = '/Temps de Lecture.{1,20}? Fiche/';
190
+ $content = preg_replace($pattern, ' ', $content);
191
+ $pattern = '/Temps de Lecture.{1,20}? min./';
192
+ $content = preg_replace($pattern, ' ', $content);
193
+
194
+ // Media-specific cutting rules
195
+ if( substr_count( $url, ".elle.fr" ) ){
196
+ $pattern = '/Note :.{13,45}? sur 5/';
197
+ $content = preg_replace($pattern, ' ', $content);
198
+ $content = str_replace( strstr( $content, " sur 5 " ), '', $content );
199
+ }
200
+
201
+ if( substr_count( $url, ".latribune.fr" ) ){
202
+ $content = str_replace( "Partager :", ' ', $content );
203
+ }
204
+
205
+ if( substr_count( $url, ".techno-science.net" ) ){
206
+ $content = strip_tags( strstr( $htmlContent, "suivez-nous sur" ) );
207
+ $content = strstr( $content, ');' );
208
+ $content = html_entity_decode( str_replace( strstr( $content, "Référence" ), "", $content ) );
209
+ }
210
+
211
+ if( substr_count( $url, ".lexpress.fr" ) ){
212
+ $content = strstr( $htmlContent, "article__text" ) ;
213
+ $content = strstr( $content, ">" );
214
+ $content = substr( $content,1,99999 );
215
+ $content = html_entity_decode( strip_tags( str_replace( strstr( $content, "<div id=\"taboola" ), "", $content ) ) );
216
+ }
217
+
218
+ $content_or = $content; // Store the original content
219
+
220
+ // List of starting phrases to find and use as the new starting point
221
+ $startPhrases = [
222
+ "Partager l'article sur Twitter",
223
+ " au sommaire ",
224
+ "TF1 INFO",
225
+ "Licence Creative Commons",
226
+ " / AFP ",
227
+ "ne rien louper de vos programmes favoris.",
228
+ "© Belga"
229
+ ];
230
+
231
+ foreach ( $startPhrases as $phrase ) {
232
+ if ( strpos( $content, $phrase ) !== false ) {
233
+ $content = strstr( $content, $phrase );
234
+ $content = str_replace( $phrase, ' ', $content );
235
+ break;
236
+ }
237
+ }
238
+
239
+ // List of phrases to remove from the end of content
240
+ $removePhrasesEnd = [
241
+ 'Sur le même sujet',
242
+ 'Sur lemême thème',
243
+ 'Nos articles à lire aussi',
244
+ 'Suivez toute l’actualité de vos villes',
245
+ 'En direct',
246
+ "J'ai déjà un compte",
247
+ '> Ecoutez',
248
+ 'Courrier international',
249
+ 'Vous avez trouvé une erreur?',
250
+ 'Il vous reste',
251
+ 'Partager',
252
+ "Suivez-nous",
253
+ 'Newsletter',
254
+ 'Abonnez-vous',
255
+ '1€ le premier mois',
256
+ 'Votre France Bleu',
257
+ 'Soyez le premier à commenter cet article',
258
+ 'Pour rester informé(e)',
259
+ 'Un site du groupe',
260
+ "Cet article est réservé aux abonnés",
261
+ "Recevez chaque vendredi l'essentiel",
262
+ "Suivez toute l'actualité de ZDNet",
263
+ "Suivez-nous sur les résaux sociaux",
264
+ ". par ",
265
+ "Le résumé de la semaine",
266
+ "ACTUELLEMENT EN KIOSQUE",
267
+ " L’actualité par la rédaction de",
268
+ "Gratis onbeperkt",
269
+ "Débloquez immédiatement cet article",
270
+ "À voir également",
271
+ "null null null ",
272
+ 'Du lundi au vendredi, à 19h',
273
+ "La rédaction de La Tribune",
274
+ "Restez toujours informé: suivez-nous sur Google Actualités",
275
+ "Du lundi au vendredi, votre rendez-vous",
276
+ "Enregistrer mon nom, mon e-mail",
277
+ "Mot de passe oublié",
278
+ '(function',
279
+ ];
280
+
281
+ foreach ( $removePhrasesEnd as $phrase ) {
282
+ $content = str_replace( strstr( $content, $phrase ), "", $content);
283
+ }
284
+
285
+ // List of phrases to remove
286
+ $removePhrases = [
287
+ "Inscrivez-vous pour recevoir les newsletters de la Rép' dans votre boîte mail",
288
+ "TF1 INFO",
289
+ "Sujet TF1 Info",
290
+ "Sujet JT LCI",
291
+ "TF1 Info ",
292
+ "JT 20h WE ",
293
+ "JT 20h Semaine ",
294
+ "Source :",
295
+ "Inscrivez-vous aux newsletters de la RTBF Tous les sujets de l'article",
296
+ "Pour voir ce contenu, connectez-vous gratuitement",
297
+ ">> LIRE AUSSI",
298
+ "À LIRE AUSSI",
299
+ "A lire aussi >> ",
300
+ " → À LIRE.",
301
+ "À voir également",
302
+ "Image d'illustration -",
303
+ "Le média de la vie locale ",
304
+ "Les plus lus.",
305
+ "Ce live est à présent terminé.",
306
+ " . -",
307
+ "[…]",
308
+ "[.]",
309
+ "(…)",
310
+ "(.)",
311
+ "©"
312
+ ];
313
+
314
+ foreach ( $removePhrases as $phrase ) {
315
+ $content = str_replace( $phrase, ".", $content );
316
+ }
317
+ $content = preg_replace( '/\.{2,}/', '.', $content );
318
+ $content = preg_replace( '/\s{2,}/', ' ', $content );
319
+ $content = preg_replace( '/-{2,}/', '-', $content );
320
+ $content = preg_replace( '/__{2,}/', '_', $content );
321
+
322
+ // Display
323
+ echo "<span style='font-family: verdana;font-size: .9em;'>($id_source) [$current_encoding] $url <br /><br />" .
324
+ "<b>Title: $title</b> <br /><br />" .
325
+ "<span style='color:$color;'>Content: $content</span>";
326
+
327
+ if( strlen( $content ) != strlen( $content_or ) ){
328
+ echo "<hr> <span style='color:#ff0000;'>$content_or</span>"; // original content
329
+ }
330
+
331
+ // Formatting the output content for the txt file in the $add variable
332
+ $content = strip_tags($content);
333
+ $add = html_entity_decode( $title ) . '. ';
334
+ if( trim( $txt_clean ) != '' ) $add .= str_replace( "..", ".", html_entity_decode( $txt_clean ) . '. ' );
335
+ if( strlen( $content ) > 160 ) $add .= $content . '.';
336
+ $add = trim( clean_text( $add ) );
337
+
338
+ $remove = [ '. .', '..', "?.", "!.", ";.", "??", "? ?",];
339
+ foreach ( $remove as $phrase ) {
340
+ $add = str_replace( $phrase, substr( $phrase,0,1 ). ' ', $add );
341
+ }
342
+ $add = strip_tags( $add );
343
+ $add = str_replace( html_entity_decode( '&nbsp;' ), " ", $add );
344
+ $add = preg_replace( '/&#(x[0-9a-fA-F]+|\d+);/', ' ', $add );
345
+ $add = preg_replace( '/&#\d+;/', ' ', $add );
346
+ $add = preg_replace( '/[\x{1F534}\x{26A0}\x{1F3C9}\x{1F6A8}\x{1F6D2}\x{1FA82}\x{25B6}\x{2139}\x{2600}-\x{26FF}\x{1F300}-\x{1F5FF}\x{1F600}-\x{1F64F}\x{1F680}-\x{1F6FF}\x{1F700}-\x{1F77F}\x{1F780}-\x{1F7FF}\x{1F800}-\x{1F8FF}\x{1F900}-\x{1F9FF}\x{1FA00}-\x{1FA6F}\x{1FA70}-\x{1FAFF}]/u', ' ', $add );
347
+ $add = preg_replace( '/\s{2,}/', ' ', $add );
348
+
349
+ $replacements = array( "À" => "À", "Â" => "Â", "Ã" => "Ã", "Ä" => "Ä", "Â" => "Â", "Ã…" => "Å", "á" => "á", "â" => "â", "ã" => "ã", "ä" => "ä", "Ã¥" => "å", "Ã’" => "Ò", "Ó" => "Ó", "Ô" => "Ô", "Õ" => "Õ", "Ö" => "Ö", "Ø" => "Ø", "ò" => "ò", "ó" => "ó", "ô" => "ô", "õ" => "õ", "ö" => "ö", "ø" => "ø", "È" => "È", "É" => "É", "Ê" => "Ê", "Ë" => "Ë", "è" => "è", "é" => "é", "ê" => "ê", "ë" => "ë", "Ç" => "Ç", "ç" => "ç", "ÃŒ" => "Ì", "ÃŽ" => "Î", "ì" => "ì", "í" => "í", "î" => "î", "ï" => "ï", "Ù" => "Ù", "Ú" => "Ú", "Û" => "Û", "Ãœ" => "Ü", "ù" => "ù", "ú" => "ú", "û" => "û", "ü" => "ü", "ÿ" => "ÿ", "Ñ" => "Ñ", "ñ" => "ñ", "Á" => "Á", "Í" => "Í", "à " => "à", '’'=>'\'', "«" => "«", '»'=>'»');
350
+ $add = str_replace( array_keys( $replacements ), array_values( $replacements ), $add );
351
+
352
+
353
+ // Additional display for debugging and testing
354
+ if( $debug ){
355
+ if( trim( $content )=='' ) {
356
+ echo "<hr /> html:<br /> $html " . htmlentities( $html ) . "<hr />" .
357
+ htmlentities( $doc->text() ) .'<br />' .
358
+ 'Source lenght: ' . strlen( $htmlContent );
359
+ }
360
+ $test_char ="";
361
+ foreach ( str_split( $add ) as $char) {
362
+ $test_char .= $char . "(" . bin2hex($char). ") ";
363
+ }
364
+ echo '<hr /> hexadecimal code for each character from $add var: <br />' . $test_char;
365
+ } else {
366
+ if( $id_source%10000 === 0 ) mysqli_query( $mysqli, "OPTIMIZE TABLE `base_news`;" );
367
+ }
368
+
369
+ // Saving the title + description + text in a text file
370
+ $key_title = md5( $title );
371
+ $nb_base = mysqli_return_number( $mysqli, "SELECT `id` FROM `base_news` WHERE `key_title`='$key_title' LIMIT 1" );
372
+
373
+ if( isset( $_GET["id"] ) OR isset( $_GET["media"] ) OR ( strlen( $content ) > 200 AND !$nb_base ) ){
374
+ mysqli_query( $mysqli, "UPDATE `base_news` SET `key_title` = '$key_title' WHERE `id`='$id_source' LIMIT 1" );
375
+
376
+ $bom = "\xEF\xBB\xBF";
377
+ file_put_contents( "$path/sources/txt_news/$id_source.txt", $bom . $add );
378
+ }
379
+
380
+ $execution_time = microtime(true) - $time_start;
381
+ echo"<hr /> execution time: $execution_time";
382
+ if( $id_source%100 === 0 ) sleep(1); // throttling navigation to prevent the browser from hanging.
383
+ if( $redirect_enabled ) echo "<script type=\"text/javascript\">location.href='" . str_replace( strstr( $_SERVER ['REQUEST_URI'], '?' ), "", $_SERVER ['REQUEST_URI'] ) . "?id=$next';</script>";
384
+
385
+
386
+ ?>
extract_news/4_extract_news_url.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * News Links Extractor
5
+ *
6
+ * Extracts and stores relevant links from local French online news articles.
7
+ *
8
+ * To use this script, you must have electrolinux/phpquery installed. Install it using Composer with
9
+ * the command: composer require electrolinux/phpquery.
10
+ *
11
+ * @author Guillaume Eckendoerffer
12
+ * @date 08-09-2023
13
+ */
14
+
15
+ // composer require electrolinux/phpquery
16
+ require 'vendor/autoload.php';
17
+
18
+ // Include the database functions
19
+ include("functions_mysqli.php");
20
+
21
+ $path = $_SERVER ['DOCUMENT_ROOT'];
22
+
23
+ /**
24
+ * Get the base domain path from a given URL
25
+ *
26
+ * @param string $url The input URL
27
+ * @return string|false The base domain path or false on failure
28
+ */
29
+ function getDomPath( $url ) {
30
+ $parsedUrl = parse_url( $url );
31
+ if ( !$parsedUrl || !isset( $parsedUrl['scheme'] ) || !isset( $parsedUrl['host'] ) ) {
32
+ return false;
33
+ }
34
+ return "{$parsedUrl['scheme']}://{$parsedUrl['host']}";
35
+ }
36
+
37
+ // Query the database for a news source with no link
38
+ $result = mysqli_query( $mysqli, "SELECT `id`, `url`, `media` FROM `base_news` WHERE `link`='0' AND `step` > 0 ORDER BY Rand() LIMIT 1" ); // AND `media` > 214
39
+ $row = mysqli_fetch_assoc( $result );
40
+ if (!$row) {
41
+ exit('No unprocessed news source found.');
42
+ }
43
+
44
+ $id_source = $row["id"];
45
+ $url_source = trim( $row["url"] );
46
+ $id_media = $row["media"];
47
+ $last = date( "U" );
48
+ $dom = getDomPath( $url_source );
49
+
50
+ echo "<span style='font-family: verdana;font-size: .9em;'>$id_source) $url_source => $dom <br /><br />";
51
+
52
+ // Mark the source as processed
53
+ mysqli_query($mysqli, "UPDATE `base_news` SET `link`='1' WHERE `id`='$id_source' LIMIT 1");
54
+
55
+ // Load the source content
56
+ $htmlContent = '';
57
+ $file_path = "$path/sources/html_news/$id_source.txt";
58
+ if ( file_exists( $file_path ) ){
59
+ $htmlContent = implode( '', file( $file_path ) );
60
+ } else {
61
+ echo "<script type=\"text/javascript\">location.href='" . $_SERVER['REQUEST_URI'] . "';</script>";
62
+ }
63
+
64
+ $doc = \phpQuery::newDocument($htmlContent);
65
+
66
+ foreach ( $doc['a'] as $link ) {
67
+ $url = trim( pq( $link )->attr( 'href' ) );
68
+ $url = str_replace( strstr( $url, "#" ), "", $url );
69
+ $url = str_replace( strstr( $url, "?utm"), "", $url );
70
+ $url = str_replace(strstr( $url, "?xtor"), "", $url );
71
+
72
+ if ( !substr_count( $url, "//" ) ) {
73
+ $url = ( substr( $url, 0, 1 ) != '/' ) ? $dom . '/' . $url : $dom . $url;
74
+ } elseif( !substr_count( $url, "http" ) ){
75
+ $url = 'https:' . $url;
76
+ }
77
+
78
+ $key = md5( $url );
79
+
80
+ $nb_base_news = mysqli_return_number($mysqli, "SELECT `id` FROM `base_news` WHERE `url` LIKE '$url%' OR `key_media`='$key' LIMIT 1");
81
+
82
+ if (substr($url, 0, strlen($dom)) != $dom) {
83
+ // Not the source domain
84
+ // echo "<span style='color:#000;'># $url </span><br />";
85
+ } elseif ($nb_base_news) {
86
+ // Already in the database
87
+ // echo "<span style='color:#FFA500;'># $url </span><br />";
88
+ } elseif (substr_count($url, "-") > 6 && substr_count($url, $dom) && !substr_count( $url, '.jpg' ) && !substr_count( $url, '.png' ) && !substr_count( $url, 'mailto' ) ) {
89
+ // Add the link to the database
90
+ echo "<span style='color:#008000;'># $url </span><br />";
91
+ $insertQuery = "INSERT INTO `base_news` (`id`, `key_media`, `media`, `url`, `step`) VALUES (NULL, '$key', '$id_media', '$url', '0');";
92
+ mysqli_query($mysqli, $insertQuery);
93
+ }
94
+ }
95
+
96
+ // Refresh the page
97
+ echo "<script type=\"text/javascript\">location.href='" . $_SERVER['REQUEST_URI'] . "';</script>";
98
+
99
+ ?>
100
+
extract_news/README.md ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # NEWS FR
3
+
4
+ The "NEWS FR" module allows for the extraction of online press articles from over a hundred different sources.
5
+
6
+ ## Installation
7
+
8
+ To set up the module, follow the steps below:
9
+
10
+ 1. **Database Setup**:
11
+ - Create a database and incorporate the two tables present in `database.sql`.
12
+
13
+ 2. **Database Configuration**:
14
+ - Update your MySQL connection information in the `functions_mysqli.php` file.
15
+
16
+ 3. **Dependencies Installation**:
17
+ - The script requires the installation of `electrolinux/phpquery`. Install it using composer:
18
+ ```
19
+ composer require electrolinux/phpquery
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ### 1. 1_extract_rss.php:
25
+
26
+ This script fetches RSS feeds from various media outlets and adds URLs for further extraction.
27
+
28
+ ```bash
29
+ php 1_extract_rss.php
30
+ ```
31
+
32
+ ### 2. 2_extract_news.php:
33
+
34
+ This script retrieves the sources of articles for subsequent local processing.
35
+
36
+ ```bash
37
+ php 2_extract_news.php
38
+ ```
39
+
40
+ ### 3. 3_extract_news_txt.php:
41
+
42
+ This script extracts the text content of press articles and saves it (title + description + text) to a `.txt` file.
43
+
44
+ ```bash
45
+ php 3_extract_news_txt.php
46
+ ```
47
+ After completing this step, you can use the Python script located at /dataset/2_cleaning_txt.py to standardize the text for your dataset.
48
+
49
+ ### 4. 4_extract_news_url.php:
50
+
51
+ This script allows for the extraction of links to other articles from local article sources. This ensures swift retrieval of numerous past articles, as opposed to fetching only the most recent ones.
52
+
53
+ ```bash
54
+ php 4_extract_news_url.php
55
+ ```
56
+ After using this script, you'll need to run 2_extract_news.php again to retrieve the sources of the new articles, as well as 3_extract_news_txt.php to extract the text from these articles.
57
+
58
+ ---
59
+
60
+ PHP + MySQL was chosen for this section to facilitate debugging, and to allow display by source or by media.
extract_news/database.sql ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --
2
+ -- Structure de la table `base_media`
3
+ --
4
+
5
+ DROP TABLE IF EXISTS `base_media`;
6
+ CREATE TABLE IF NOT EXISTS `base_media` (
7
+ `id` int NOT NULL AUTO_INCREMENT,
8
+ `url` varchar(255) NOT NULL,
9
+ `nb` int NOT NULL,
10
+ `last` int NOT NULL,
11
+ PRIMARY KEY (`id`)
12
+ ) ENGINE=MyISAM CHARSET=utf8mb4;
13
+
14
+ --
15
+ -- Déchargement des données de la table `base_media`
16
+ --
17
+
18
+ INSERT INTO `base_media` (`id`, `url`, `nb`, `last`) VALUES
19
+ (1, 'https://www.lemonde.fr/rss/une.xml', 0, 0),
20
+ (2, 'https://www.liberation.fr/arc/outboundfeeds/collection/accueil-une/?outputType=xml', 0, 0),
21
+ (3, 'https://www.lemonde.fr/international/rss_full.xml', 0, 0),
22
+ (4, 'https://www.lemonde.fr/europe/rss_full.xml', 0, 0),
23
+ (5, 'https://www.lemonde.fr/politique/rss_full.xml', 0, 0),
24
+ (6, 'https://www.lemonde.fr/economie/rss_full.xml', 0, 0),
25
+ (7, 'https://www.lemonde.fr/culture/rss_full.xml', 0, 0),
26
+ (8, 'https://www.lemonde.fr/sport/rss_full.xml', 0, 0),
27
+ (9, 'https://www.lemonde.fr/sciences/rss_full.xml', 0, 0),
28
+ (10, 'https://www.lemonde.fr/rss/en_continu.xml', 0, 0),
29
+ (15, 'https://www.bfmtv.com/rss/news-24-7/', 0, 0),
30
+ (16, 'https://www.bfmtv.com/rss/international/', 0, 0),
31
+ (17, 'https://www.bfmtv.com/rss/politique/', 0, 0),
32
+ (18, 'https://www.bfmtv.com/rss/sciences/', 0, 0),
33
+ (19, 'https://www.bfmtv.com/rss/police-justice/', 0, 0),
34
+ (20, 'https://www.bfmtv.com/rss/people/cinema/', 0, 0),
35
+ (21, 'https://www.bfmtv.com/rss/tech/', 0, 0),
36
+ (22, 'https://www.bfmtv.com/rss/economie/', 0, 0),
37
+ (23, 'https://www.bfmtv.com/rss/paris/', 0, 0),
38
+ (24, 'https://www.bfmtv.com/rss/lyon/', 0, 0),
39
+ (25, 'https://www.bfmtv.com/rss/grand-lille/', 0, 0),
40
+ (26, 'https://www.bfmtv.com/rss/grand-littoral/', 0, 0),
41
+ (27, 'https://www.bfmtv.com/rss/marseille/', 0, 0),
42
+ (28, 'https://www.bfmtv.com/rss/var/', 0, 0),
43
+ (29, 'https://www.bfmtv.com/rss/cote-d-azur/', 0, 0),
44
+ (30, 'https://www.bfmtv.com/rss/toulouse/', 0, 0),
45
+ (31, 'https://www.bfmtv.com/rss/ajaccio/', 0, 0),
46
+ (32, 'https://www.bfmtv.com/rss/auxerre/', 0, 0),
47
+ (33, 'https://www.bfmtv.com/rss/bastia/', 0, 0),
48
+ (34, 'https://www.bfmtv.com/rss/besancon/', 0, 0),
49
+ (35, 'https://www.bfmtv.com/rss/bordeaux/', 0, 0),
50
+ (36, 'https://www.bfmtv.com/rss/brest/', 0, 0),
51
+ (37, 'https://www.bfmtv.com/rss/caen/', 0, 0),
52
+ (38, 'https://www.bfmtv.com/rss/clermont-ferrand/', 0, 0),
53
+ (39, 'https://www.bfmtv.com/rss/dijon/', 0, 0),
54
+ (40, 'https://www.bfmtv.com/rss/grenoble/', 0, 0),
55
+ (41, 'https://www.bfmtv.com/rss/la-rochelle/', 0, 0),
56
+ (42, 'https://www.bfmtv.com/rss/le-havre/', 0, 0),
57
+ (43, 'https://www.bfmtv.com/rss/limoges/', 0, 0),
58
+ (44, 'https://www.bfmtv.com/rss/metz/', 0, 0),
59
+ (45, 'https://www.bfmtv.com/rss/montpellier/', 0, 0),
60
+ (46, 'https://www.bfmtv.com/rss/nancy/', 0, 0),
61
+ (47, 'https://www.bfmtv.com/rss/nantes/', 0, 0),
62
+ (48, 'https://www.bfmtv.com/rss/orleans/', 0, 0),
63
+ (49, 'https://www.bfmtv.com/rss/poitiers/', 0, 0),
64
+ (50, 'https://www.bfmtv.com/rss/reims/', 0, 0),
65
+ (51, 'https://www.bfmtv.com/rss/rennes/', 0, 0),
66
+ (52, 'https://www.bfmtv.com/rss/saint-etienne/', 0, 0),
67
+ (53, 'https://www.bfmtv.com/rss/strasbourg/', 0, 0),
68
+ (54, 'https://www.bfmtv.com/rss/tours/', 0, 0),
69
+ (55, 'https://www.cnews.fr/rss.xml', 0, 0),
70
+ (56, 'https://www.francetvinfo.fr/titres.rss', 0, 0),
71
+ (57, 'https://www.francetvinfo.fr/france.rss', 0, 0),
72
+ (58, 'https://www.francetvinfo.fr/politique.rss', 0, 0),
73
+ (59, 'https://www.francetvinfo.fr/societe.rss', 0, 0),
74
+ (60, 'https://www.francetvinfo.fr/faits-divers.rss', 0, 0),
75
+ (61, 'https://www.francetvinfo.fr/justice.rss', 0, 0),
76
+ (62, 'https://www.francetvinfo.fr/monde.rss', 0, 0),
77
+ (63, 'https://www.francetvinfo.fr/economie.rss', 0, 0),
78
+ (64, 'https://www.francetvinfo.fr/sports.rss', 0, 0),
79
+ (65, 'https://www.francetvinfo.fr/decouverte.rss', 0, 0),
80
+ (66, 'https://www.francetvinfo.fr/culture.rss', 0, 0),
81
+ (67, 'https://www.france24.com/fr/rss', 0, 0),
82
+ (68, 'https://www.france24.com/fr/europe/rss', 0, 0),
83
+ (69, 'https://www.france24.com/fr/france/rss', 0, 0),
84
+ (70, 'https://www.france24.com/fr/afrique/rss', 0, 0),
85
+ (71, 'https://www.france24.com/fr/moyen-orient/rss', 0, 0),
86
+ (72, 'https://www.france24.com/fr/ameriques/rss', 0, 0),
87
+ (73, 'https://www.france24.com/fr/asie-pacifique/rss', 0, 0),
88
+ (74, 'https://www.france24.com/fr/economie/rss', 0, 0),
89
+ (75, 'https://www.france24.com/fr/sports/rss', 0, 0),
90
+ (76, 'https://www.france24.com/fr/culture/rss', 0, 0),
91
+ (77, 'https://www.lefigaro.fr/rss/figaro_actualites.xml', 0, 0),
92
+ (78, 'https://www.lefigaro.fr/rss/figaro_politique.xml', 0, 0),
93
+ (79, 'https://www.lefigaro.fr/rss/figaro_elections.xml', 0, 0),
94
+ (80, 'https://www.lefigaro.fr/rss/figaro_international.xml', 0, 0),
95
+ (81, 'https://www.lefigaro.fr/rss/figaro_actualite-france.xml', 0, 0),
96
+ (82, 'https://www.lefigaro.fr/rss/figaro_sciences.xml', 0, 0),
97
+ (83, 'https://www.lefigaro.fr/rss/figaro_economie.xml', 0, 0),
98
+ (84, 'https://www.lefigaro.fr/rss/figaro_culture.xml', 0, 0),
99
+ (85, 'https://www.lefigaro.fr/rss/figaro_flash-actu.xml', 0, 0),
100
+ (86, 'https://www.lefigaro.fr/rss/figaro_sport.xml', 0, 0),
101
+ (87, 'https://www.rtl.fr/sitemap-news.xml', 0, 0),
102
+ (88, 'https://www.tf1info.fr/sitemap-n.xml', 0, 0),
103
+ (89, 'https://www.latribune.fr/feed.xml', 0, 0),
104
+ (90, 'https://www.humanite.fr/rss/actu.rss', 0, 0),
105
+ (91, 'https://www.la-croix.com/RSS/UNIVERS', 0, 0),
106
+ (92, 'https://www.la-croix.com/RSS/UNIVERS_WFRA', 0, 0),
107
+ (93, 'https://www.la-croix.com/RSS/WMON-EUR', 0, 0),
108
+ (94, 'https://www.la-croix.com/RSS/WECO-MON', 0, 0),
109
+ (95, 'https://www.nicematin.com/googlenews.xml', 0, 0),
110
+ (96, 'https://www.ouest-france.fr/rss/une', 0, 0),
111
+ (97, 'https://www.midilibre.fr/rss.xml', 0, 0),
112
+ (99, 'https://www.laprovence.com/googlenews.xml', 0, 0),
113
+ (100, 'https://www.sudouest.fr/rss.xml', 0, 0),
114
+ (101, 'https://www.sudouest.fr/culture/cinema/rss.xml', 0, 0),
115
+ (102, 'https://www.sudouest.fr/economie/rss.xml', 0, 0),
116
+ (103, 'https://www.sudouest.fr/faits-divers/rss.xml', 0, 0),
117
+ (104, 'https://www.sudouest.fr/politique/rss.xml', 0, 0),
118
+ (105, 'https://www.sudouest.fr/sport/rss.xml', 0, 0),
119
+ (98, 'https://feeds.leparisien.fr/leparisien/rss', 0, 0),
120
+ (107, 'https://www.lexpress.fr/sitemap_actu_1.xml', 0, 0),
121
+ (108, 'https://www.lepoint.fr/rss.xml', 0, 0),
122
+ (109, 'https://www.lepoint.fr/politique/rss.xml', 0, 0),
123
+ (110, 'https://www.lepoint.fr/monde/rss.xml', 0, 0),
124
+ (111, 'https://www.lepoint.fr/societe/rss.xml', 0, 0),
125
+ (112, 'https://www.lepoint.fr/economie/rss.xml', 0, 0),
126
+ (113, 'https://www.lepoint.fr/medias/rss.xml', 0, 0),
127
+ (114, 'https://www.lepoint.fr/science/rss.xml', 0, 0),
128
+ (115, 'https://www.lepoint.fr/sport/rss.xml', 0, 0),
129
+ (116, 'https://www.lepoint.fr/high-tech-internet/rss.xml', 0, 0),
130
+ (117, 'https://www.lepoint.fr/culture/rss.xml', 0, 0),
131
+ (118, 'https://www.nouvelobs.com/sport/rss.xml', 0, 0),
132
+ (119, 'https://www.nouvelobs.com/societe/rss.xml', 0, 0),
133
+ (120, 'https://www.nouvelobs.com/politique/rss.xml', 0, 0),
134
+ (121, 'https://www.nouvelobs.com/justice/rss.xml', 0, 0),
135
+ (122, 'https://www.nouvelobs.com/faits-divers/rss.xml', 0, 0),
136
+ (123, 'https://www.nouvelobs.com/economie/rss.xml', 0, 0),
137
+ (124, 'https://www.nouvelobs.com/culture/rss.xml', 0, 0),
138
+ (125, 'https://www.nouvelobs.com/monde/rss.xml', 0, 0),
139
+ (161, 'https://www.football365.fr/feed', 0, 0),
140
+ (127, 'https://www.europe1.fr/rss.xml', 0, 0),
141
+ (128, 'https://www.europe1.fr/rss/sport.xml', 0, 0),
142
+ (129, 'https://www.europe1.fr/rss/politique.xml', 0, 0),
143
+ (130, 'https://www.europe1.fr/rss/international.xml', 0, 0),
144
+ (131, 'https://www.europe1.fr/rss/technologies.xml', 0, 0),
145
+ (132, 'https://www.europe1.fr/rss/faits-divers.xml', 0, 0),
146
+ (133, 'https://www.europe1.fr/rss/economie.xml', 0, 0),
147
+ (134, 'https://www.europe1.fr/rss/culture.xml', 0, 0),
148
+ (135, 'https://www.europe1.fr/rss/societe.xml', 0, 0),
149
+ (136, 'https://www.europe1.fr/rss/sciences.xml', 0, 0),
150
+ (137, 'https://www.europe1.fr/rss/insolite.xml', 0, 0),
151
+ (138, 'https://www.lalibre.be/arc/outboundfeeds/rss/section/belgique/?outputType=xml', 0, 0),
152
+ (139, 'https://www.lalibre.be/arc/outboundfeeds/rss/section/economie/?outputType=xml', 0, 0),
153
+ (140, 'https://www.lalibre.be/arc/outboundfeeds/rss/section/international/?outputType=xml', 0, 0),
154
+ (141, 'https://www.lalibre.be/arc/outboundfeeds/rss/section/culture/?outputType=xml', 0, 0),
155
+ (142, 'https://www.lalibre.be/arc/outboundfeeds/rss/section/sports/?outputType=xml', 0, 0),
156
+ (143, 'https://www.lalibre.be/arc/outboundfeeds/rss/section/regions/?outputType=xml', 0, 0),
157
+ (144, 'https://www.courrierinternational.com/feed/all/rss.xml', 0, 0),
158
+ (145, 'https://www.20minutes.fr/feeds/rss-une.xml', 0, 0),
159
+ (146, 'https://www.huffingtonpost.fr/rss/all_headline.xml', 0, 0),
160
+ (147, 'https://fr.euronews.com/sitemaps/fr/latest-news.xml', 0, 0),
161
+ (148, 'https://www.dhnet.be/arc/outboundfeeds/rss/section/actu/belgique/?outputType=xml', 0, 0),
162
+ (149, 'https://www.dhnet.be/arc/outboundfeeds/rss/section/actu/faits/?outputType=xml', 0, 0),
163
+ (150, 'https://www.dhnet.be/arc/outboundfeeds/rss/section/actu/societe/?outputType=xml', 0, 0),
164
+ (151, 'https://www.dhnet.be/arc/outboundfeeds/rss/section/actu/monde/?outputType=xml', 0, 0),
165
+ (152, 'https://www.dhnet.be/arc/outboundfeeds/rss/section/actu/economie/?outputType=xml', 0, 0),
166
+ (153, 'https://www.dhnet.be/arc/outboundfeeds/rss/section/sports/?outputType=xml', 0, 0),
167
+ (154, 'https://www.dhnet.be/arc/outboundfeeds/rss/section/regions/?outputType=xml', 0, 0),
168
+ (155, 'https://www.rtbf.be/site-map/articles.xml', 0, 0),
169
+ (156, 'https://www.lematin.ch/sitemaps/fr/news.xml', 0, 0),
170
+ (157, 'https://www.24heures.ch/sitemaps/news.xml', 0, 0),
171
+ (158, 'https://www.20min.ch/sitemaps/fr/news.xml', 0, 0),
172
+ (159, 'https://www.tdg.ch/sitemaps/news.xml', 0, 0),
173
+ (160, 'https://www.lequipe.fr/sitemap/sitemap_google_news_gratuit.xml', 0, 0),
174
+ (162, 'http://feeds.feedburner.com/SoFoot', 0, 0),
175
+ (163, 'https://rmcsport.bfmtv.com/rss/football/', 0, 0),
176
+ (164, 'https://rmcsport.bfmtv.com/rss/rugby/', 0, 0),
177
+ (165, 'https://rmcsport.bfmtv.com/rss/basket/', 0, 0),
178
+ (166, 'https://rmcsport.bfmtv.com/rss/tennis/', 0, 0),
179
+ (167, 'https://rmcsport.bfmtv.com/rss/cyclisme/', 0, 0),
180
+ (168, 'https://rmcsport.bfmtv.com/rss/auto-moto/f1/', 0, 0),
181
+ (169, 'https://rmcsport.bfmtv.com/rss/handball/', 0, 0),
182
+ (170, 'https://rmcsport.bfmtv.com/rss/jeux-olympiques/', 0, 0),
183
+ (171, 'https://rmcsport.bfmtv.com/rss/football/ligue-1/', 0, 0),
184
+ (172, 'https://rmcsport.bfmtv.com/rss/sports-de-combat/', 0, 0),
185
+ (174, 'https://www.francebleu.fr/rss/a-la-une.xml', 0, 0),
186
+ (175, 'https://www.journaldunet.com/rss/', 0, 0),
187
+ (176, 'https://www.lindependant.fr/rss.xml', 0, 0),
188
+ (177, 'https://www.lopinion.fr/index.rss', 0, 0),
189
+ (178, 'https://www.marianne.net/rss.xml', 0, 0),
190
+ (179, 'https://www.01net.com/actualites/feed/', 0, 0),
191
+ (181, 'https://www.brut.media/fr/rss', 0, 0),
192
+ (182, 'https://www.lamontagne.fr/sitemap.xml', 0, 0),
193
+ (183, 'https://www.science-et-vie.com/feed', 0, 0),
194
+ (184, 'https://fr.motorsport.com/rss/all/news/', 0, 0),
195
+ (185, 'https://www.presse-citron.net/feed/', 0, 0),
196
+ (186, 'https://www.valeursactuelles.com/feed?post_type=post&taxonomy_name=cult', 0, 0),
197
+ (187, 'https://www.valeursactuelles.com/feed?post_type=post&taxonomy_name=faits-di', 0, 0),
198
+ (188, 'https://www.larepubliquedespyrenees.fr/actualite/rss.xml', 0, 0),
199
+ (189, 'https://actu17.fr/feed', 0, 0),
200
+ (191, 'https://www.futura-sciences.com/rss/actualites.xml', 0, 0),
201
+ (192, 'https://www.techno-science.net/include/news.xml', 0, 0),
202
+ (193, 'https://trashtalk.co/feed', 0, 0),
203
+ (194, 'https://regards.fr/feed/', 0, 0),
204
+ (195, 'https://www.allocine.fr/rss/news.xml', 0, 0),
205
+ (229, 'https://www.jeuxvideo.com/rss/rss.xml', 0, 0),
206
+ (230, 'https://www.clubic.com/feed/news.rss', 0, 0),
207
+ (231, 'https://www.letelegramme.fr/rss.xml', 0, 0),
208
+ (232, 'https://www.sciencesetavenir.fr/rss.xml', 0, 0),
209
+ (200, 'https://www.onzemondial.com/rss/index.html', 0, 0),
210
+ (226, 'https://www.petitbleu.fr/rss.xml', 0, 0),
211
+ (227, 'https://www.centrepresseaveyron.fr/rss.xml', 0, 0),
212
+ (228, 'https://www.toulouscope.fr/rss.xml', 0, 0),
213
+ (205, 'https://www.7sur7.be/people/rss.xml', 0, 0),
214
+ (206, 'https://www.7sur7.be/sport/rss.xml', 0, 0),
215
+ (207, 'https://www.7sur7.be/monde/rss.xml', 0, 0),
216
+ (208, 'https://www.7sur7.be/belgique/rss.xml', 0, 0),
217
+ (210, 'https://cdn-elle.ladmedia.fr/var/plain_site/storage/flux_rss/fluxToutELLEfr.xml', 0, 0),
218
+ (211, 'https://www.santemagazine.fr/feeds/rss', 0, 0),
219
+ (212, 'https://www.santemagazine.fr/feeds/rss/actualites', 0, 0),
220
+ (214, 'https://www.abcbourse.com/rss/displaynewsrss', 0, 0),
221
+ (213, 'https://actu.fr/rss.xml', 0, 0),
222
+ (225, 'https://www.rugbyrama.fr/rss.xml', 0, 0),
223
+ (224, 'https://www.ladepeche.fr/rss.xml', 0, 0),
224
+ (235, 'https://services.lesechos.fr/rss/les-echos-economie.xml', 0, 0),
225
+ (223, 'https://www.femmeactuelle.fr/feeds/rss.xml', 0, 0),
226
+ (233, 'https://air-cosmos.com/rss', 0, 0),
227
+ (236, 'https://services.lesechos.fr/rss/les-echos-entreprises.xml', 0, 0),
228
+ (237, 'https://services.lesechos.fr/rss/les-echos-finance-marches.xml', 0, 0),
229
+ (238, 'https://www.numerama.com/feed/', 0, 0);
230
+ COMMIT;
231
+
232
+ -- --------------------------------------------------------
233
+
234
+ --
235
+ -- Structure de la table `base_news`
236
+ --
237
+
238
+ DROP TABLE IF EXISTS `base_news`;
239
+ CREATE TABLE IF NOT EXISTS `base_news` (
240
+ `id` int NOT NULL AUTO_INCREMENT,
241
+ `key_media` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
242
+ `key_title` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
243
+ `media` int NOT NULL,
244
+ `title` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
245
+ `txt_clean` text NOT NULL,
246
+ `url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
247
+ `link` tinyint NOT NULL,
248
+ `step` tinyint NOT NULL,
249
+ PRIMARY KEY (`id`),
250
+ KEY `url` (`url`(250)),
251
+ KEY `key_title` (`key_title`),
252
+ KEY `key_media` (`key_media`),
253
+ KEY `media` (`media`)
254
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
255
+ COMMIT;
256
+
extract_news/functions_mysqli.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ #####################################################################
4
+ ###################### Base fonctions mysqli ####################
5
+ #####################################################################
6
+
7
+
8
+ $mysqli = new mysqli("[host]", "[user]", "[passwd]", "[database]");
9
+ if ($mysqli->connect_errno) {
10
+ echo "Failed to connect to MySQL : (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
11
+ }
12
+
13
+ function mysqli_return_number( $mysqli, $req ){
14
+
15
+ $row_cnt = 0;
16
+ if ( $result = $mysqli->query( "$req" ) ) {
17
+
18
+ $row_cnt = $result->num_rows;
19
+ $result->close();
20
+ }
21
+ return $row_cnt;
22
+ }
23
+
24
+
25
+
26
+
27
+
28
+
29
+ ?>
extract_news/sources/html_news/.gitkeep ADDED
File without changes
extract_news/sources/rss/.gitkeep ADDED
File without changes
extract_news/sources/txt_news/.gitkeep ADDED
File without changes