Created
January 9, 2017 13:53
-
-
Save techman83/2efcaa9b086b674368441aedf9860953 to your computer and use it in GitHub Desktop.
Script for changing download links to the Internet archive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use 5.018; | |
use File::Find::Rule; | |
use Data::Dumper; | |
use App::KSP_CKAN::Metadata::Ckan; | |
my @ckans = File::Find::Rule->file()->name('*.ckan' )->in( "CKAN-meta/." ); | |
foreach my $ckan (@ckans) { | |
my $meta = App::KSP_CKAN::Metadata::Ckan->new( | |
file => $ckan, | |
); | |
if ($meta->download =~ /^http:\/\/ckan1.spacedock.info/) { | |
my $archive_url = "https://archive.org/download/".$meta->mirror_item."/" . $meta->mirror_filename; | |
my $download = $meta->download; | |
open(FILE, "<$ckan") || die "File not found"; | |
my @lines = <FILE>; | |
close(FILE); | |
my @newlines; | |
foreach(@lines) { | |
$_ =~ s/"download": "$download",/"download": "$archive_url",/g; | |
push(@newlines,$_); | |
} | |
open(FILE, ">$ckan") || die "File not found"; | |
print FILE @newlines; | |
close(FILE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment