-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWikiJSONimages.txt
More file actions
40 lines (29 loc) · 1.2 KB
/
WikiJSONimages.txt
File metadata and controls
40 lines (29 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!perl
use JSON qw( decode_json encode_json );
use Data::Dumper;
use URI::Escape "uri_unescape";
use strict;
use warnings;
my $json = join"",<>;
# Decode the entire JSON
my $decoded_json = decode_json( $json );
#print Dumper $decoded_json;
my $items = $decoded_json->{'items'};
for (@$items){
my $desc;
if ($_->{'type'}=~/image/){
eval {$desc = $_->{'description'}{'text'}};
$_->{'original'}{'source'} =~ /.*\/(.*?\..*)/;
if (!defined $_->{'original'}{'source'}){next;}
my $nick = uri_unescape($1);
utf8::decode($nick);
my $name = $_->{'caption'}{'text'} // ($desc=~/(^[\w ]+)/)[0];
for ($desc,$name){ s/\bSee(:| here\b).*?(\n|\.(?!\w))//g; }
$desc =~ s/\n{2,}/\n/g;
my $caption = "$desc\n\nSource: $_->{'original'}{'source'}";
my $URL = $_->{'original'}{'source'};
if ($_->{'license'}{'code'}=~/^(cc|PD|OldOS|Stamp-PD|FAL|OGL|MPL|GFD|GPL|LGPL|BSD)/){print encode_json({ "command"=> "save", "url"=> "$URL", "record_type"=> "medium", "data"=> {
"name"=> "$name", "content"=> "$caption", "nickname"=> "wkpd-$nick", "subtype"=> "picture"}
})};
}
}