Skip to content

Commit

Permalink
добавлены методы для наполнения всеми страницами БД. В последсвии буд…
Browse files Browse the repository at this point in the history
…ут проверяться только последние ревизии
  • Loading branch information
Ichinya committed Dec 5, 2020
1 parent c7552f1 commit f7a7631
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
25 changes: 18 additions & 7 deletions cContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class cContent
{
protected $urlAPI;
protected string $urlAPI;
protected string $fileParams;
protected $params;

Expand All @@ -23,6 +23,15 @@ public function __construct($urlAPI)
return $this->params = json_decode($json, true);
}

public function initParamFile($file)
{
if (!file_exists($file)) {
return false;
}
$json = file_get_contents($file);
return json_decode($json, true);
}

/**
* получаем данные от АПИ
* @param array $params параметры обращения
Expand All @@ -41,16 +50,18 @@ protected function getContent(array $params): array
/**
* при запросах, где ответы от АПИ превышают одну страницу - считываем все страницы
* @param array $params параметры обращения к АПИ
* @return array ответ от АПИ
* @return array|null ответ от АПИ
*/
protected function getContentAll(array $params): array
protected function getContentAll(array $params)
{
$out = $this->getContent($params);
$result = $out['query']['recentchanges'];
while ($out['query-continue']['recentchanges']['rccontinue'] != "") {
$params['rccontinue'] = $out['query-continue']['recentchanges']['rccontinue'];
$result = $out['query'][$params['list']];
while ($out['query-continue'][$params['list']]['rccontinue'] != "" ||
$out['query-continue'][$params['list']]['apcontinue'] != "") {
$params['rccontinue'] = $out['query-continue'][$params['list']]['rccontinue'];
$params['apcontinue'] = $out['query-continue'][$params['list']]['apcontinue'];
$out = $this->getContent($params);
$result = array_merge($result, $out['query']['recentchanges']);
$result = array_merge($result, $out['query'][$params['list']]);
}
return $result;
}
Expand Down
21 changes: 21 additions & 0 deletions cPageList.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ public function __construct($config)
$this->getPages();
}

public function init()
{
$params = $this->initParamFile("params_init.json");
$pagesIndex = $this->getContentAll($params);
$pages = [];
foreach ($pagesIndex as $pageIndex) {
$page = new cPage(
$pageIndex['pageid'],
$pageIndex['title'],
date(DATE_RFC822, 0));
$pages[] = $page;
}
return $pages;
}

function getPages()
{
$list = $this->getContentAll($this->params);
Expand Down Expand Up @@ -64,6 +79,12 @@ public function getPageId($id)
return $this->convertArrayToPage($pageDB);
}

public function countPageDB()
{
$db = new cDB();
return $db->getCountPage();
}

public function countPage()
{
return count($this->listPage);
Expand Down
7 changes: 5 additions & 2 deletions cParse.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ function fillingURL()
/**
* получаем данные страницы (текст в формате html и список категорий)
* @param int $id ИД страницы
* @return array массив с данными
* @return array|null массив с данными
*/
private function parsePageByPageId(int $id): array
private function parsePageByPageId(int $id)
{
$params = $this->params;
$params['pageid'] = $id;
Expand All @@ -69,6 +69,9 @@ private function parsePageByPageId(int $id): array
private function updatePageByPage(cPage &$page)
{
$parse = $this->parsePageByPageId($page->id);
if (!is_array($parse)) {
return false;
}
$page->text = $parse['text']['*'];
$page->revid = $parse['revid'];
if (is_array($parse['categories'])) {
Expand Down
10 changes: 10 additions & 0 deletions params_init.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"action": "query",
"format": "json",
"list": "allpages",
"iwurl": 1,
"rawcontinue": 1,
"aplimit": "2",
"utf8": 1,
"formatversion": "2"
}
10 changes: 10 additions & 0 deletions params_init_page.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"action": "query",
"format": "json",
"list": "allpages",
"iwurl": 1,
"rawcontinue": 1,
"aplimit": "2",
"utf8": 1,
"formatversion": "2"
}
5 changes: 2 additions & 3 deletions params_page_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"utf8": 1,
"formatversion": "2",
"rcdir": "older",
"rcprop": "title|timestamp|ids|revid|user",
"rclimit": "500",
"rctoponly": 1
"rcprop": "title|timestamp|ids|user",
"rclimit": "500"
}
1 change: 0 additions & 1 deletion params_page_parse.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
"prop": "text|categories|categorieshtml|revid|langlinks|headhtml|url",
"disableeditsection": 1,
"utf8": 1

}

0 comments on commit f7a7631

Please sign in to comment.