User:Nichalp/code2

From Wikipedia, the free encyclopedia

Code[edit]

#! /usr/bin/perl
# Testing.plx

use strict;
use warnings;

my ($current_name, $new_name, $description_language, $description, $author, $date, $permission, $other_version1, $other_version2, $coordinate, $latitude, $latitude_ref, $longitude, $longitude_ref, $geo_type, $geo_region, $geo_scale, $geo_heading, $geo_reference, $category_1, $category_2, $category_3, $category_4, $category_5, $rotation, $altitude, $time_zone, $country, $state, $flick, $flickr_title, $flickr_url, $flickr_photographer_url, $place, $camera, $model, $aperture, $shutter, $film, $iso, $lens);
my $err=0;
my $line;
my ($geo_parameters);

open(FILELIST,"<testing.csv") 
  or die "Could not find file list";

<FILELIST>; #<-- skips first line

while(<FILELIST>) {
	$line= $_;
	chomp($line);
	$line=~tr/"//d; #removes the double quotes
	#splitting the CSV file by comma
	($current_name, $new_name, $description_language, $description, $author, $date, $permission, $other_version1, $other_version2, $coordinate, $latitude, $latitude_ref, $longitude, $longitude_ref, $geo_type, $geo_scale, $geo_region, $geo_heading, $geo_reference, $category_1, $category_2, $category_3, $category_4, $category_5, $rotation, $altitude, $time_zone, $country, $state, $flick, $flickr_title, $flickr_url, $flickr_photographer_url, $place, $camera, $model, $aperture, $shutter, $film, $iso, $lens) = split ',' , $line;


# Check to see if compulsory fields Description, Permissions, and Category has been added. Warn if not.
	if ($description eq ""){print "Please add a description to $current_name\n" ;$err=1;};
 	if ($permission eq ""){print "Please add licensing information to $current_name\n";$err=1;};
	if ($category_1 eq ""){print "Please enter a category\n"; $err=1;};


# Check to see if both latitude and longitude are given, and one is not missing. If both do not exist, ignore.
	if (($latitude ne "") xor ($longitude ne ""))
		{
		if($latitude eq "") 
		 {
		   print "Please add the latitude to $current_name\n";
		  } 
		if($longitude eq "")
		 {
		   print "Please add the longitude to $current_name\n";
		 }
		if($latitude_ref eq "")
		 {
		   print "Please add the latitude reference (N or S) to $current_name\n";
		 }
		if($longitude_ref eq "")
		 {
		   print "Please add the longitude reference (E or W) to $current_name\n";
		 }
		$err=1;
		}

#################################
#Gathering and formatting geo parameters
		if ($geo_type ne "")
		  {$geo_parameters.="type:$geo_type\_";};
		if ($geo_scale ne "")
		  {$geo_parameters.="scale:$geo_scale\_";};		
		if ($geo_region ne "")
		  {$geo_parameters.="region:$geo_region\_";};
		if ($geo_heading ne "")
		  {$geo_parameters.="heading:$geo_heading\_";};	
		if ($geo_reference ne "")
		  {$geo_parameters.="source:$geo_reference";};
		$geo_parameters=~s/^_*//; # Remove leading underscore
		$geo_parameters=~s/_*$//; # Remove trailing underscore


#################################
# This checks to see if the Geo Location box is needed, and fills in the values
	if (($latitude ne "") && ($longitude ne "") && (($coordinate eq 'd') || ($coordinate="")))
		{
		$geo_reference="{{Location dec|$latitude|$longitude|$geo_parameters}}\n";}
	elsif ((($latitude ne "") && ($longitude ne "")) && ($coordinate eq "dms"))
		{
		$geo_reference="{{Location|$latitude|$latitude_ref|$longitude|$longitude_ref|$geo_parameters}}\n";		
		}		
		print "$geo_reference";
#################################		

}

if ($err == 1) 
	{die "Please add the above values and try again...\n\n";}

testing.cvs[edit]

"Current name","New name","Description lang","Description","Author","Date","Permission","Other versions 1","Other versions 2","Coordinate","Latitude","Latitude Ref","Longitude","Longitude Ref","Type","Scale","Region","Heading","Reference","Category1","Category2","Category3","Category4","Category5","Rotation","Altitude","Time Zone","Country","State","Flickr","Flickr title","URL","Photographer URL","Reviewer","Camera","Model","Aperture","Shutter","Film","ISO","Lens"
"img1.jpg",,"en","test image","Nicholas",26/06/08,"GFDL",,,"d",55,"N",22,"E","landmark",2000,"IN-MH",234,"ORTS","Beaches",,,,,,,,,,,,,,,,,,,,,