public/Misc/PerlScript/create_SiteMap_XML.pl


 

#To create siteMap.xml file
#Before running this script edit searchAutocomplete.js i.e. delete unwanted lines from top and bottom of this page.. lines which does not contain url
#!/usr/bin/perl

main ();
sub main {
   processInput();
   createXML();
}


sub createXML {

print " ${fileR}   and ${fileC} \n";


   open(MASTER,$fileR);
   my @contents = <MASTER>;
   close(MASTER);

   open(FILE,">$fileC");
   print FILE "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
   print FILE "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">";

   my @manualContent = ('home', 'login', 'contactus', 'RegionWise', 'India/type/Hill-Stations', 'India/type/Honeymoon-Sites', 'India/type/Beaches', 'India/type/Natural-Scenic-Places', 'India/type/Adventurous-Sports-Activity', 'India/type/Historical-Monuments', 'India/type/Religious-Places', 'India/type/Wild-Life-Sanctuary');
   foreach my $list (@manualContent) {
     print FILE "\n<url>\n";
     print FILE "  <loc>https://www.spotdekho.com/$list</loc>\n";
     print FILE "  <changefreq>weekly</changefreq>\n";
     print FILE "  <priority>1.00</priority>\n";
     print FILE "</url>\n";
   }

   foreach my $line (@contents) {
     chomp($line);
     my @splitL = split("\"",$line);
     print "$splitL[3]  $splitL[5] \n";
     print FILE "\n<url>\n";
     print FILE "  <loc>https://www.spotdekho.com/$splitL[3]$splitL[5]</loc>\n";
     print FILE "  <changefreq>weekly</changefreq>\n";
     print FILE "  <priority>0.70</priority>\n";
     print FILE "</url>\n";
   }
   print FILE "</urlset>";
   close (FILE);

}

sub processInput {

    my $arg = "";
    my $opt = "";
    if ($#ARGV == -1) {
       printusage();
     }
    while ($#ARGV != -1) {
        $arg = join(" ", @ARGV);
        $opt = shift(@ARGV);
        if ($opt =~ /^-h(elp)?$/){
           printusage();
        } elsif ($opt =~ /^-fileR/) {
           if (($#ARGV != -1) && ($ARGV[0] !~ /^-/)) {
               $fileR = shift(@ARGV);
           } else {
             print "option $opt requires atleast one argument\n";
             exit;
           }
        } elsif ($opt =~ /^-fileC/) {
           if (($#ARGV != -1) && ($ARGV[0] !~ /^-/)) {
               $fileC = shift(@ARGV);
           } else {
             print "option $opt requires atleast one argument\n";
             exit;
           }
        } else {
             print "\nINVALID OPTION!\n\n";
             printusage();
        }
    }
}


sub printusage() {
        print "\n Before running this script edit searchAutocomplete.js i.e. delete unwanted lines from top and bottom of this page.. lines which does not contain url. \n\n";
        print "USAGE : $0 -fileR <File_name i.e. \"searchAutocomplete.js\" should be in same directory from where this script is running> -fileC <sitemap.xml> -h[elp]\n";
        print "\n-fileR\t:\t File_name i.e. \"searchAutocomplete.js\" should be in same directory from where this script is running ";
        print "\n-fileC\t:\tsitemap.xml\n";
        print "For Example, the following command :\n";
        print "sudo perl create_SiteMap_XML.pl -fileR searchAutocomplete.js -fileC sitemap.xml\n\n";
        exit;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *