Revision 828 (by ahitrov, 2021/09/08 15:14:48) CDEK getter

#!/usr/bin/perl

use strict;
use warnings "all";
use locale;

use FindBin;
BEGIN {
	require "$FindBin::RealBin/../lib/Modules.pm";
}

use Contenido::Globals;
use Contenido::Init;
use ErrorTee;
use PidFile;
use Data::Dumper;

# begin
Contenido::Init->init();

my $keeper_module = $state->project.'::Keeper';
$keeper = $keeper_module->new($state);

#PidFile->new($keeper, compat=>1);                # db-based locking (run only on one host)
#PidFile->new($keeper, compat=>1, per_host=>1);   # db-based locking (run on whole cluster)

# Plugins init
for my $plugin ( split(/\s+/, $state->plugins) ) {
	my $class = $plugin.'::Apache';
	eval { $class->child_init(); };
	if ( $@ ) {
		$log->error("Не могу выполнить метод child_init плагина $plugin ($class) по причине '$@'");
	}
}

############################################
# please use:
#     $state->{log_dir} for logging
#     $state->{tmp_dir} for temporary files
###########################################
my $file_tmp = $state->{data_dir}.'/cdekGetPVZ.tmp.dump';
my $file_russia = $state->{data_dir}.'/cdekGetPVZ_rus.dump';
my $file_all = $state->{data_dir}.'/cdekGetPVZ_all.dump';

my $cdek = webshop::Service::CDEK->new();

my $langPart = '&lang=rus';
my $result = $cdek->_MakeRequest( 'https://integration.cdek.ru/pvzlist/v1/json?type=ALL' . $langPart, 'get', undef, { expires_at => 30 * 3600 } );

my $res = $cdek->getPVZ({ lang => 'rus', country => 'Россия', no_cache => 1, raw_data => $result });

open FH, "> $file_tmp";
print FH Dumper $res;
close FH;
rename $file_tmp, $file_russia;

$res = $cdek->getPVZ({ lang => 'rus', country => 'all', no_cache => 1, raw_data => $result });

open FH, "> $file_tmp";
print FH Dumper $res;
close FH;
rename $file_tmp, $file_all;