1 |
828 |
ahitrov |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use warnings "all"; |
5 |
|
|
use locale; |
6 |
|
|
|
7 |
|
|
use FindBin; |
8 |
|
|
BEGIN { |
9 |
|
|
require "$FindBin::RealBin/../lib/Modules.pm"; |
10 |
|
|
} |
11 |
|
|
|
12 |
|
|
use Contenido::Globals; |
13 |
|
|
use Contenido::Init; |
14 |
|
|
use ErrorTee; |
15 |
|
|
use PidFile; |
16 |
|
|
use Data::Dumper; |
17 |
|
|
|
18 |
|
|
# begin |
19 |
|
|
Contenido::Init->init(); |
20 |
|
|
|
21 |
|
|
my $keeper_module = $state->project.'::Keeper'; |
22 |
|
|
$keeper = $keeper_module->new($state); |
23 |
|
|
|
24 |
|
|
#PidFile->new($keeper, compat=>1); # db-based locking (run only on one host) |
25 |
|
|
#PidFile->new($keeper, compat=>1, per_host=>1); # db-based locking (run on whole cluster) |
26 |
|
|
|
27 |
|
|
# Plugins init |
28 |
|
|
for my $plugin ( split(/\s+/, $state->plugins) ) { |
29 |
|
|
my $class = $plugin.'::Apache'; |
30 |
|
|
eval { $class->child_init(); }; |
31 |
|
|
if ( $@ ) { |
32 |
|
|
$log->error("Не могу выполнить метод child_init плагина $plugin ($class) по причине '$@'"); |
33 |
|
|
} |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
############################################ |
37 |
|
|
# please use: |
38 |
|
|
# $state->{log_dir} for logging |
39 |
|
|
# $state->{tmp_dir} for temporary files |
40 |
|
|
########################################### |
41 |
|
|
my $file_tmp = $state->{data_dir}.'/cdekGetPVZ.tmp.dump'; |
42 |
|
|
my $file_russia = $state->{data_dir}.'/cdekGetPVZ_rus.dump'; |
43 |
|
|
my $file_all = $state->{data_dir}.'/cdekGetPVZ_all.dump'; |
44 |
|
|
|
45 |
|
|
my $cdek = webshop::Service::CDEK->new(); |
46 |
|
|
|
47 |
|
|
my $langPart = '&lang=rus'; |
48 |
|
|
my $result = $cdek->_MakeRequest( 'https://integration.cdek.ru/pvzlist/v1/json?type=ALL' . $langPart, 'get', undef, { expires_at => 30 * 3600 } ); |
49 |
|
|
|
50 |
|
|
my $res = $cdek->getPVZ({ lang => 'rus', country => 'Россия', no_cache => 1, raw_data => $result }); |
51 |
|
|
|
52 |
|
|
open FH, "> $file_tmp"; |
53 |
|
|
print FH Dumper $res; |
54 |
|
|
close FH; |
55 |
|
|
rename $file_tmp, $file_russia; |
56 |
|
|
|
57 |
|
|
$res = $cdek->getPVZ({ lang => 'rus', country => 'all', no_cache => 1, raw_data => $result }); |
58 |
|
|
|
59 |
|
|
open FH, "> $file_tmp"; |
60 |
|
|
print FH Dumper $res; |
61 |
|
|
close FH; |
62 |
|
|
rename $file_tmp, $file_all; |