Commits

shl...@52c325ad-5fd0-0310-8a0f-c43feede02cc  committed b145f8c

Added the scripts.

  • Participants

Comments (0)

Files changed (2)

File 1st-version-as-scripts/prepare-yaml.pl

+#!/usr/bin/perl 
+
+use strict;
+use warnings;
+
+use File::Spec;
+use YAML;
+
+opendir my $cwd, ".";
+my @paths = sort { $a cmp $b } grep { /\.(jpg|png)$/ } (File::Spec->no_upwards(readdir($cwd)));
+closedir ($cwd);
+
+my $yaml_fn = "upload-spec.yml";
+if (-e $yaml_fn)
+{
+    die "YAML File already exists!";
+}
+open my $yaml, ">", $yaml_fn;
+print {$yaml} Dump(
+    {
+        common_tags => "",
+        files =>
+        [
+            (map
+            {
+                {
+                    'filename' => $_,
+                    'tags' => [],
+                    title => "",
+                    description_parts => 
+                    [ map { "" } (1 .. 5) ],
+                }
+            }
+            @paths),
+        ],
+    }
+);
+close($yaml);
+

File 1st-version-as-scripts/upload.pl

+#!/usr/bin/perl 
+
+use strict;
+use warnings;
+
+use YAML;
+use Carp;
+
+use Flickr::Upload;
+
+my $data = YAML::LoadFile("upload-spec.yml");
+
+my $common_tags = $data->{common_tags};
+
+print "\$common_tags == $common_tags\n\n";
+
+my $files = $data->{files};
+
+foreach my $f (@$files)
+{
+    if (! -f $f->{filename})
+    {
+        confess "Unknown filename $f->{filename}!";
+    }
+}
+
+sub get_total_desc
+{
+    my $f = shift;
+    my $ret = join("\n", grep { length($_) > 0 } @{$f->{'description_parts'}});
+
+    $ret = s/\n{3,}/\n\n/g;
+
+    return $ret;
+}
+
+my $ua = Flickr::Upload->new(
+    {
+        key => "80ae1c17f5096f699b46a8256b918d2f",
+        secret => "167830a9c74f74ac",
+    }
+);
+
+open my $log, ">>", "dump.txt";
+foreach my $f (@$files)
+{
+    $ua->upload(
+            auth_token => '72157600129103080-4c0f738e272f0348',
+            photo => "./" .$f->{filename},
+            tags => "$common_tags $f->{tags}",
+            title => $f->{'title'},
+            description => get_total_desc($f),,
+            is_public => 1,
+    ) or die "Unknown";
+    print {$log} $f->{filename}, "\n";
+    $log->flush();
+}
+close($log);
+