Issues (12)

parser.php (1 issue)

Labels
Severity
1
<?php
2
require 'vendor/autoload.php';
3
4
$client = new \GuzzleHttp\Client();
5
$year = isset($argv[1]) ? $argv[1] : date('Y');
6
$uri = "http://www.consultant.ru/law/ref/calendar/proizvodstvennye/$year/";
7
8
$response = $client->get($uri);
9
$content = phpQuery::newDocument($response->getBody()->getContents());
0 ignored issues
show
$response->getBody()->getContents() of type string is incompatible with the type unknown_type expected by parameter $markup of phpQuery::newDocument(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

9
$content = phpQuery::newDocument(/** @scrutinizer ignore-type */ $response->getBody()->getContents());
Loading history...
10
$dates = file_exists('holidays.json') ? json_decode(file_get_contents('holidays.json'), true) : [];
11
$dates[$year] = [
12
    'holidays' => [],
13
    'works' => [],
14
    'preholidays' => [],
15
    'weekend' => []
16
];
17
$m = 0;
18
foreach ($content->find('.cal') as $table) {
19
    $query = pq($table);
20
    $m++;
21
    foreach ($query->find('td') as $td) {
22
        $month = str_pad($m, 2, '0', STR_PAD_LEFT);
23
        $day = str_pad(preg_replace('/[\D]/', '', pq($td)->text()), 2, '0', STR_PAD_LEFT);
24
        if (pq($td)->hasClass('inactively')) {
25
            continue;
26
        }
27
        $date = $year . '-' . $month . '-' . $day;
28
        $idx = 'works';
29
        if (pq($td)->hasClass('holiday')) {
30
            $idx = 'holidays';
31
        }
32
        if (in_array(date('w', strtotime($date)), ['6', '0'], true)) {
33
            $idx = 'weekend';
34
        }
35
	
36
        $dates[$year][$idx][] = $date;
37
        if (pq($td)->hasClass('preholiday')) {
38
            $dates[$year]['preholidays'][] = $date;
39
        }
40
		if (pq($td)->hasClass('work')) {
41
			$dates[$year]['works'][] = $date;
42
        }
43
    }
44
}
45
46
file_put_contents("holidays.json", json_encode($dates));