| 1 | package WWW::AzimuthAero::PriceCrawler; | ||
| 2 | $WWW::AzimuthAero::PriceCrawler::VERSION = '0.3'; | ||
| 3 | |||
| 4 | # ABSTRACT: Crawler for https://azimuth.aero/ | ||
| 5 | |||
| 6 | use parent 'WWW::AzimuthAero'; | ||
| 7 | use feature 'say'; | ||
| 8 | |||
| 9 | |||
| 10 | sub prepare_requests { | ||
| 11 | my ( $self, %params ) = @_; | ||
| 12 | |||
| 13 | my $iata_map = $self->route_map->route_map_iata( $params{cities} ); | ||
| 14 | |||
| 15 | my $n = 0; | ||
| 16 | if ( $params{verbose} ) { | ||
| 17 | say 'Cities total: ' . scalar keys %$iata_map if $params{verbose}; | ||
| 18 | for my $x ( values %$iata_map ) { | ||
| 19 | $n += scalar @$x; | ||
| 20 | } | ||
| 21 | say | ||
| 22 | 'Amount of WWW::AzimuthAero::get_schedule_dates HTTP requests will be performed: ' | ||
| 23 | if $params{verbose}; | ||
| 24 | } | ||
| 25 | |||
| 26 | my @get_requests; | ||
| 27 | while ( ( $from, $cities ) = each(%$iata_map) ) { | ||
| 28 | for my $to (@$cities) { | ||
| 29 | say "$n : get_schedule_dates : $from -> $to" if $params{verbose}; | ||
| 30 | $n-- if $params{verbose}; | ||
| 31 | my @dates = $self->get_schedule_dates( from => $from, to => $to ); | ||
| 32 | for my $date (@dates) { | ||
| 33 | push @get_requests, { from => $from, to => $to, date => $date }; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | if ( $params{verbose} ) { | ||
| 39 | say 'Amount of WWW::AzimuthAero::get HTTP requests will be performed: ' | ||
| 40 | . scalar @get_requests | ||
| 41 | if $params{verbose}; | ||
| 42 | say 'Total HTTP requests: ' . $n + scalar @get_requests | ||
| 43 | if $params{verbose}; | ||
| 44 | } | ||
| 45 | |||
| 46 | return @get_requests; | ||
| 47 | |||
| 48 | } | ||
| 49 | |||
| 50 | 1; | ||
| 51 | |||
| 52 | __END__ | ||
| 53 | |||
| 54 | =pod | ||
| 55 | |||
| 56 | =encoding UTF-8 | ||
| 57 | |||
| 58 | =head1 NAME | ||
| 59 | |||
| 60 | WWW::AzimuthAero::PriceCrawler - Crawler for https://azimuth.aero/ | ||
| 61 | |||
| 62 | =head1 VERSION | ||
| 63 | |||
| 64 | version 0.3 | ||
| 65 | |||
| 66 | =head1 SYNOPSIS | ||
| 67 | |||
| 68 | my $azo_price_crawler = WWW::AzimuthAero::PriceCrawler->new(); | ||
| 69 | $azo_price_crawler->prepare_requests() | ||
| 70 | |||
| 71 | =head1 DESCRIPTION | ||
| 72 | |||
| 73 | Wrappper under L<WWW::AzimuthAero> | ||
| 74 | |||
| 75 | =head1 METHODS | ||
| 76 | |||
| 77 | =head2 new | ||
| 78 | |||
| 79 | See L<WWW::AzimuthAero/new> | ||
| 80 | |||
| 81 | =head2 prepare_requests | ||
| 82 | |||
| 83 | Return arrray of hashes with params (from, to, date) for WWW::AzimuthAero::get method | ||
| 84 | |||
| 85 | my @l = $azo_price_crawler->prepare_requests( max_date => '18.12.2019', verbose => 1, cities => [ qw/ROV LED/ ] ); | ||
| 86 | |||
| 87 | In fact, combines L<WWW::AzimuthAero::RouteMap/route_map_iata> and L<WWW::AzimuthAero/get_schedule_dates> | ||
| 88 | |||
| 89 | =head3 Params | ||
| 90 | |||
| 91 | max_date - '%d.%m.%Y' format, if no specified will looks forward for 2 months, default max_date of L<WWW::AzimuthAero/get_schedule_dates> | ||
| 92 | |||
| 93 | verbose - print amount of L<WWW::AzimuthAero/get_schedule_dates> requests and future amount of L<WWW::AzimuthAero/get> requests | ||
| 94 | |||
| 95 | cities - filter for L<WWW::AzimuthAero::RouteMap/route_map_iata> | ||
| 96 | |||
| 97 | =head1 AUTHOR | ||
| 98 | |||
| 99 | Pavel Serikov <pavelsr@cpan.org> | ||
| 100 | |||
| 101 | =head1 COPYRIGHT AND LICENSE | ||
| 102 | |||
| 103 | This software is copyright (c) 2019 by Pavel Serikov. | ||
| 104 | |||
| 105 | This is free software; you can redistribute it and/or modify it under | ||
| 106 | the same terms as the Perl 5 programming language system itself. | ||
| 107 | |||
| 108 | =cut |