script/filmaffinity-get-all-info.pl untested

filter: Statementstmt 0.0% 0 / 84 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 15 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 127 CC 1 SCAR 6.9
CC
1
Cov
0%
setFileSystem
2.0
getListOfLocalMovieId
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2  
3 use strict;
4 use warnings;
5  
6 use Getopt::Long;
7 use Pod::Usage;
8  
9 use Carp;
10 use English qw/-no_match_vars/;
11 use Readonly;
12 use IO::All -utf8;
13 use List::Compare;
14 use IO::Interactive qw/is_interactive/;
15 use FilmAffinity::Movie;
16 use FilmAffinity::Utils qw/data2tsv/;
17 use FilmAffinity::UserRating;
18  
19 =head1 NAME
20  
21 filmaffinity-get-all-info.pl
22  
23 =head1 DESCRIPTION
24  
25 Get information from filmaffinity about a film and all ratings from a user
26  
27 =head1 VERSION
28  
29 Version 0.10
30  
31 =head1 USAGE
32  
33 ./filmaffinity-get-all-info.pl --userid=123456 --destination=path/to/my/folder
34  
35 ./filmaffinity-get-all-info.pl --userid=123456 --destination=path/to/my/folder --delay=2
36  
37 ./filmaffinity-get-all-info.pl --userid=123456 --destination=path/to/my/folder --force
38  
39 =head1 REQUIRED ARGUMENTS
40  
41 =over 2
42  
43 =item --userid=123456
44  
45 userid from filmaffinity
46  
47 =item --destination=/home/william/filmaffinity
48  
49 destination folder
50  
51 =back
52  
53 =head1 OPTIONS
54  
55 =over 2
56  
57 =item --delay=3
58  
59 delay between requests
60  
61 =item --force
62  
63 force to retrieve all movies
64  
65 =back
66  
67 =cut
68  
69 our $VERSION = '0.10';
70  
71 my ( $userID, $delay, $destination, $force, $help );
72  
73 GetOptions(
74 'userid=i' => \$userID,
75 'delay=i' => \$delay,
76 'destination=s' => \$destination,
77 'force' => \$force,
78 'help' => \$help,
79 ) || pod2usage(2);
80  
81 if ( $help || !$userID || !$destination ) {
82 pod2usage(1);
83 exit 0;
84 }
85  
86 setFileSystem();
87  
88 my $userParser = FilmAffinity::UserRating->new(
89 userID => $userID,
90 delay => $delay || $DELAY,
91 );
92 my $ref_movies = $userParser->parse();
93 my $tsv = data2tsv($ref_movies);
94 $tsv > io( $destination . '/ratings.list' );
95  
96 my @listOfRemoteMovieId = keys %{$ref_movies};
97 my @listOfLocalMovieId = getListOfLocalMovieId();
98  
99 my $listCompare =
100 List::Compare->new( \@listOfLocalMovieId, \@listOfRemoteMovieId, );
101  
102 my @listOfMovieToRetrieve =
103 $force ? @listOfRemoteMovieId : $listCompare->get_Ronly();
104  
105 my $progress;
106 if ( is_interactive() ) {
107 my $value = eval {
108 require Term::ProgressBar;
109 $progress = Term::ProgressBar->new(
110 {
111 name => 'jsonize movie information',
112 count => scalar @listOfMovieToRetrieve,
113 remove => 1
114 }
115 );
116 };
117 if ($EVAL_ERROR) {
118 carp
119 'Could not create progress bar. We can continue, but no progress will be reported';
120 }
121 }
122  
123 my $count = 0;
124 foreach my $id (@listOfMovieToRetrieve) {
125  
126 my $movie = FilmAffinity::Movie->new(
127 id => $id,
128 delay => $delay || $DELAY,
129 );
130 $movie->parse();
131 $movie->myrating( $ref_movies->{$id}->{rating} );
132  
133 my $json = $movie->toJSON();
134 $json > io( $destination . '/json/' . $id . '.json' );
135  
136 $count++;
137 $progress->update($count) if $progress;
138 }
139  
140 sub setFileSystem {
141 mkdir $destination;
142 mkdir $destination . '/json';
143 return;
144 }
145  
146 sub getListOfLocalMovieId {
147 my @listOfLocalMovie = ();
148 my @content = io( $destination . '/json' )->all();
149 foreach my $file (@content) {
150 my $filename = $file->filename;
151 $filename =~ s/[.]json//xms;
152 push @listOfLocalMovie, $filename;
153 }
154 return @listOfLocalMovie;
155 }
156  
157 =head1 AUTHOR
158  
159 William Belle, C<< <william.belle at gmail.com> >>
160  
161 =head1 BUGS AND LIMITATIONS
162  
163 Please report any bugs or feature requests to C<bug-filmaffinity-userrating at rt.cpan.org>, or through
164 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=FilmAffinity-UserRating>. I will be notified, and then you'll
165 automatically be notified of progress on your bug as I make changes.
166  
167 =head1 SUPPORT
168  
169 You can find documentation for this module with the perldoc command.
170  
171 perldoc filmaffinity-get-all-info.pl
172  
173 You can also look for information at:
174  
175 =over 4
176  
177 =item * RT: CPAN's request tracker (report bugs here)
178  
179 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=FilmAffinity-UserRating>
180  
181 =item * AnnoCPAN: Annotated CPAN documentation
182  
183 L<http://annocpan.org/dist/FilmAffinity-UserRating>
184  
185 =item * CPAN Ratings
186  
187 L<http://cpanratings.perl.org/d/FilmAffinity-UserRating>
188  
189 =item * Search CPAN
190  
191 L<http://search.cpan.org/dist/FilmAffinity-UserRating/>
192  
193 =back
194  
195 =head1 SEE ALSO
196  
197 L<http://www.filmaffinity.com>
198  
199 =head1 LICENSE AND COPYRIGHT
200  
201 Copyright 2013 William Belle.
202  
203 This program is free software; you can redistribute it and/or modify it
204 under the terms of either: the GNU General Public License as published
205 by the Free Software Foundation; or the Artistic License.
206  
207 See http://dev.perl.org/licenses/ for more information.
208  
209 =cut