Commits

shl...@iglu.org.il@cec68495-dca5-4e2b-845c-11fdaaa4f967  committed 5f95210

Start extracting a class for the gen-prod-synd scripts.

  • Participants
  • Parent commits 69ecf24

Comments (0)

Files changed (5)

 $(T2_SRC_DIR)/art/recommendations/music/index.html.wml : $(PROD_SYND_MUSIC_INC)
 	touch $@
 
-$(PROD_SYND_MUSIC_INC) : $(PROD_SYND_MUSIC_DIR)/gen-prod-synd.pl $(T2_SRC_DIR)/art/recommendations/music/shlomi-fish-music-recommendations.xml
-	perl $<
+GPERL = perl -Ilib
+GPERL_DEPS = lib/Shlomif/Homepage/Amazon.pm
+
+$(PROD_SYND_MUSIC_INC) : $(PROD_SYND_MUSIC_DIR)/gen-prod-synd.pl $(T2_SRC_DIR)/art/recommendations/music/shlomi-fish-music-recommendations.xml $(GPERL_DEPS)
+	$(GPERL) $<
 	./gen-helpers.pl
 	$(MAKE)
 
 $(T2_DEST)/philosophy/books-recommends/index.html : $(PROD_SYND_NON_FICTION_BOOKS_INC)
 
-$(PROD_SYND_NON_FICTION_BOOKS_INC) : $(PROD_SYND_NON_FICTION_BOOKS_DIR)/gen-prod-synd.pl $(T2_SRC_DIR)/philosophy/books-recommends/shlomi-fish-non-fiction-books-recommendations.xml
-	perl $<
+$(PROD_SYND_NON_FICTION_BOOKS_INC) : $(PROD_SYND_NON_FICTION_BOOKS_DIR)/gen-prod-synd.pl $(T2_SRC_DIR)/philosophy/books-recommends/shlomi-fish-non-fiction-books-recommendations.xml $(GPERL_DEPS)
+	$(GPERL) $<
 	./gen-helpers.pl
 	$(MAKE)
 
 $(T2_DEST)/humour/recommendations/films/index.html: $(PROD_SYND_FILMS_INC)
 
-$(PROD_SYND_FILMS_INC) : $(PROD_SYND_FILMS_DIR)/gen-prod-synd.pl $(T2_SRC_DIR)/humour/recommendations/films/shlomi-fish-films-recommendations.xml
-	perl $<
+$(PROD_SYND_FILMS_INC) : $(PROD_SYND_FILMS_DIR)/gen-prod-synd.pl $(T2_SRC_DIR)/humour/recommendations/films/shlomi-fish-films-recommendations.xml $(GPERL_DEPS)
+	$(GPERL) $<
 	./gen-helpers.pl
 	$(MAKE)
 

File lib/Shlomif/Homepage/Amazon.pm

+package Shlomif::Homepage::Amazon;
+
+use Moose;
+
+use Term::ReadPassword;
+
+has 'wml_dir' => (isa => 'Str', is => 'ro');
+has 'ps' => (isa => 'XML::Grammar::ProductsSyndication', is => 'ro');
+
+sub process
+{
+    my ($self) = @_;
+
+    $self->ps->update_cover_images(
+        {
+            'size' => "l",
+            'resize_to' => { 'width' => 150, 'height' => 250 },
+            'name_cb' =>
+            sub
+            {
+                my $args = shift;
+                return $self->wml_dir() . "/images/$args->{id}.jpg";
+            },
+            'amazon_token' => "0VRRHTFJECHSKYNYD282",
+            'amazon_associate' => "shlomifishhom-20",
+            'amazon_sak' => read_password('Secret Access Key: '),
+        }
+    );
+
+    return;
+}
+
+1;

File lib/prod-synd/films/gen-prod-synd.pl

 use strict;
 use warnings;
 
+use Shlomif::Homepage::Amazon;
+
 use XML::Grammar::ProductsSyndication;
-
 use XML::LibXML::XPathContext;
 
 use Term::ReadPassword;
 print {$out} $xc->findnodes('/html:html/html:body/html:div')->[0]->toString(0);
 close ($out);
 
-$ps->update_cover_images(
+Shlomif::Homepage::Amazon->new(
     {
-        'size' => "l",
-        'resize_to' => { 'width' => 150, 'height' => 250 },
-        'name_cb' =>
-            sub
-            {
-                my $args = shift;
-                return "$wml_dir/images/$args->{id}.jpg";
-            },
-        'amazon_token' => "0VRRHTFJECHSKYNYD282",
-        'amazon_associate' => "shlomifishhom-20",
-        'amazon_sak' => read_password('Secret Access Key: '),
-    }
-);
-
-1;
-
+        ps => $ps,
+        wml_dir => $wml_dir,
+    })->process;

File lib/prod-synd/music/gen-prod-synd.pl

 use strict;
 use warnings;
 
+use Shlomif::Homepage::Amazon;
+
 use XML::Grammar::ProductsSyndication;
 
 use XML::LibXML::XPathContext;
 print {$out} $xc->findnodes('/html:html/html:body/html:div')->[0]->toString(0);
 close ($out);
 
-$ps->update_cover_images(
+Shlomif::Homepage::Amazon->new(
     {
-        'size' => "l",
-        'resize_to' => { 'width' => 150, 'height' => 250 },
-        'name_cb' => 
-            sub 
-            {
-                my $args = shift;
-                return "$wml_dir/images/$args->{id}.jpg";
-            },
-        'amazon_token' => "0VRRHTFJECHSKYNYD282",
-        'amazon_associate' => "shlomifishhom-20",
-        'amazon_sak' => read_password('Secret Access Key: '),
-    }
-);
-
-1;
-
+        ps => $ps,
+        wml_dir => $wml_dir,
+    })->process;

File lib/prod-synd/non-fiction-books/gen-prod-synd.pl

 use strict;
 use warnings;
 
-use Term::ReadPassword;
+use Shlomif::Homepage::Amazon;
 
 use XML::Grammar::ProductsSyndication;
 
 print {$out} $xc->findnodes('/html:html/html:body/html:div')->[0]->toString(0);
 close ($out);
 
-$ps->update_cover_images(
+Shlomif::Homepage::Amazon->new(
     {
-        'size' => "l",
-        'resize_to' => { 'width' => 150, 'height' => 250 },
-        'name_cb' => 
-            sub 
-            {
-                my $args = shift;
-                return "$wml_dir/images/$args->{id}.jpg";
-            },
-        'amazon_token' => "0VRRHTFJECHSKYNYD282",
-        'amazon_associate' => "shlomifishhom-20",
-        'amazon_sak' => read_password('Secret Access Key: '),
-    },
-);
+        ps => $ps,
+        wml_dir => $wml_dir,
+    })->process;
 
 1;