#!/usr/bin/perl

open(FH, '<', "./aquinas_urls.txt") or die $!;

my $tick = 0;

while (<FH>) {
	$url = $_;
	$url =~ s/^.*http/http/;
	# `wget $url`;
	
	$url =~ m/.*\/(.*)$/;
	chomp $url;
	$file = $1;
	$file =~ s/\~//;

	if (-e "/home/apps1/htdocs/mathias/James/AquinasIndex/source/$file") { 
	
		open INNFIL, "<", "./source/$file";
		
		print "Reading $file";

		my $wholefile = do { local $/; <INNFIL> };

		# Strip start
		$wholefile =~ s/.*(<div id="vl_ul" .*?>)/\1/sm;

		# Strip ending
		$wholefile =~ s/<\!-- \/vList -->.*$//sm;

		close INNFIL;
		
		open UTFIL, ">", "./source/tempfil";
		print UTFIL $wholefile;
		close UTFIL;
	
		print " .. ";
		unlink "./source/$file" or die $!;
		rename "./source/tempfil", "./source/$file" or die $!;
		print "\n";
		}
	else {
		print ".sources/$file finnes ikke";
		}
	# exit;
	}