PageRenderTime 22ms CodeModel.GetById 12ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/boots/boots_list_to_kml.pl

http://scrapeshops.googlecode.com/
Perl | 68 lines | 42 code | 14 blank | 12 comment | 3 complexity | 1eb2c7ea0849adcbccca5ef0c5a553a5 MD5 | raw file
 1#!/usr/bin/perl
 2
 3use strict;
 4use warnings;
 5
 6select STDERR; $| = 1;
 7select STDOUT; $| = 1;
 8#use Template::Toolkit;
 9use Data::Dumper;
10
11# specify input filename, or file handle, text reference, etc.
12my $input = $ARGV[0] || die "need filename\n";
13
14print <<EOF;
15<?xml version="1.0" encoding="UTF-8"?>
16<!--
17	* 1st January 2010
18	* List of Boots shop locations
19	* https://code.google.com/p/scrapeshops/
20-->
21<kml xmlns="http://www.opengis.net/kml/2.2">
22EOF
23
24open(IN,'<',$input) || die $!;
25my $header = <IN>; # throw away
26
27while (my $line = <IN>) { 
28	chomp($line);
29
30	# Boots store name	Latitude	Longitude	Address1	Address2	Address3	Postcode	Phone number
31	# London Bridge St	51.501401	-0.124976	11 Bridge Street	null	null	SW1A 2JR	0207 9304571
32
33	#die "line=$line";
34	my @a = split(/\t/,$line);
35	#die "a=".Dumper(\@a);
36	my ($name, $lat, $long) = ($a[0],$a[1],$a[2]);
37	my ($phone) = ($a[7]);
38	my (@address) = ($a[3],$a[4],$a[5],$a[6]);
39	my $description = "$name ($lat,$long)\n";
40	my $formatted_address = "\n";
41	foreach my $add (@address) {
42		$formatted_address .= "$add\n";
43	}
44	$description .= "$formatted_address\n";
45	$description .= "Tel: $phone\n";
46	#die "desc=$description";
47
48	print <<EOF;
49	  <Placemark>
50	    <name>$name</name>
51	    <description>$description</description>
52	    <Point>
53	      <coordinates>$long,$lat,0</coordinates>
54	    </Point>
55	  </Placemark>
56EOF
57
58	#die "argh";
59}
60
61print "</kml>\n";
62
63close(IN);
64
65# process input template, substituting variables
66#$template->process($input, $vars)
67#	|| die $template->error();
68