1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of dispositif/wikibot application |
4
|
|
|
* 2019 : Philippe M. <[email protected]> |
5
|
|
|
* For the full copyright and MIT license information, please view the LICENSE file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace App\Application\Examples; |
11
|
|
|
|
12
|
|
|
use App\Application\Bot; |
13
|
|
|
use App\Application\WikiPageAction; |
14
|
|
|
use App\Domain\Utils\TemplateParser; |
15
|
|
|
use App\Infrastructure\DbAdapter; |
16
|
|
|
use App\Infrastructure\ServiceFactory; |
17
|
|
|
|
18
|
|
|
//use App\Application\CLI; |
19
|
|
|
|
20
|
|
|
include __DIR__.'/../myBootstrap.php'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* From json list of articles => add to SQL TempRawOpti |
24
|
|
|
*/ |
25
|
|
|
$process = new ArticleScan(); |
26
|
|
|
//$json = file_get_contents(__DIR__.'/../resources/titles.json'); |
27
|
|
|
//$articles = json_decode($json, true); |
28
|
|
|
|
29
|
|
|
$articles = file(__DIR__.'/../resources/importISBN_nov.txt'); |
30
|
|
|
|
31
|
|
|
foreach ($articles as $article) { |
32
|
|
|
$article = trim($article); |
33
|
|
|
if (empty($article)) { |
34
|
|
|
continue; |
35
|
|
|
} |
36
|
|
|
$process->pageScan($article, 0); |
37
|
|
|
sleep(4); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
class ArticleScan |
41
|
|
|
{ |
42
|
|
|
private $wiki; |
43
|
|
|
private $db; |
44
|
|
|
private $bot; |
45
|
|
|
|
46
|
|
|
public function __construct() |
47
|
|
|
{ |
48
|
|
|
$this->wiki = ServiceFactory::wikiApi(); |
49
|
|
|
$this->db = new DbAdapter(); |
50
|
|
|
$this->bot = new Bot(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function pageScan(string $title, ?int $priority = 0): bool |
54
|
|
|
{ |
55
|
|
|
sleep(2); |
56
|
|
|
echo "\n-------------------------------------\n\n"; |
57
|
|
|
echo date("Y-m-d H:i:s")."\n"; |
58
|
|
|
echo $title."\n"; |
59
|
|
|
|
60
|
|
|
$page = new WikiPageAction($this->wiki, $title); |
61
|
|
|
$text = $page->getText(); |
62
|
|
|
|
63
|
|
|
// Skip AdQ |
64
|
|
|
if (preg_match('#{{ ?En-tête label#i', $text) > 0) { |
65
|
|
|
echo "SKIP : AdQ ou BA.\n"; |
66
|
|
|
|
67
|
|
|
//$this->db->skipArticle($title); |
68
|
|
|
|
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
try { |
73
|
|
|
$parse = TemplateParser::parseAllTemplateByName('ouvrage', $text); |
|
|
|
|
74
|
|
|
} catch (\Exception $e) { |
75
|
|
|
dump($e); |
76
|
|
|
|
77
|
|
|
return false; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if (empty($parse)) { |
81
|
|
|
return false; |
82
|
|
|
} |
83
|
|
|
$data = []; |
84
|
|
|
foreach ($parse['ouvrage'] as $res) { |
85
|
|
|
$thisdata = [ |
86
|
|
|
'page' => $title, |
87
|
|
|
'raw' => $res['raw'], |
88
|
|
|
'priority' => $priority, |
89
|
|
|
]; |
90
|
|
|
// filtre doublon |
91
|
|
|
if (!in_array($thisdata, $data)) { |
92
|
|
|
$data[] = $thisdata; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$result = $this->db->insertTempRawOpti($data); |
97
|
|
|
dump($result); |
98
|
|
|
return !empty($result); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|