Perl Sitemap Generator

I think everyone has the problem to make a sitemap if you have more than 1M videos …this script counts the packets (40k) in line 19 and then make the packets to generate a sitemap.

use strict;
use warnings;
use DBI;

my $host = "";
my $database = "db";
my $tablename = "table";
my $user = "root";
my $pw = "pwd1234";

my $dbh = DBI->connect('DBI:mysql:'.$database , $user, $pw
	           ) || die "Could not connect to database: $DBI::errstr";

my $sitemap_counter = 0;
my $th = $dbh->prepare('SELECT round(count(*)/40000+0.5) FROM `video` WHERE `bw` <=80');
while (my @row = $th->fetchrow_array()) {
   $sitemap_counter = $row[0];

for my $SMP (0..$sitemap_counter){
	print "build midd".$SMP.".xml ...".$/;
	open (DATEI, "> /var/www/MAP/midd".$SMP.".xml") or die $!;
	print DATEI '<?xml version="1.0" encoding="UTF-8"?>'.$/;
	print DATEI '<urlset xmlns="">'.$/;
	$th = $dbh->prepare('SELECT CONCAT( "<url><loc>", `id` , "</loc><priority>0.8</priority></url>" ) FROM `video` WHERE `bw` <=80 ORDER BY `id` LIMIT '.(40000*$SMP).' , 40000;');
	while (my @row = $th->fetchrow_array()) {
	   print DATEI $row[0].$/;
	print DATEI '</urlset>';
	close (DATEI);
	print "[DONE]".$/;


Leave a Reply

Your email address will not be published.

nineteen − three =