Usuário(a):NTBot/Scripts

Origem: Wikipédia, a enciclopédia livre.

Os scripts que se seguem são, obviamente, GPL. © -- Nuno Tavares 22:57, 3 Mai 2005 (UTC)

massive.pl[editar | editar código-fonte]

#!/usr/bin/perl

$pt = "cmds/culturapt.txt";
$en = "cmds/culturaen.txt";
$trads = "cmds/traducoes_paises.txt";
open (FPT, "<".$pt) || die "$0: nao abriu PT\n";

while (<FPT>) {
	$orig = ""; 	$iw = "";
	$orig = $_;
	print "Original (pt): ".$orig;
	chomp($orig);

	if ( $orig =~ /Cultura \w+ (.*)\s*$/ ) {
		#print "---------------------------->MATCH!!\n";
		$tra = `cat $trads | grep "$1"`;
		chomp ($tra);
		(undef, $enpais) = split /\t/,$tra;
		if ( length($enpais) > 0 ) {
			print "Pais(en): $enpais\n";
			$iw = `cat $en | grep "$enpais" | head -1`;
			chomp($iw);
		}
		if ( length($iw) <= 0 ) {
			print "Equivalente (en): ";
			$iw = <STDIN>;
			chomp($iw);	
		}
	}
	if (open(TTT,"<cmds/unicodes.txt") ) {
		while (<TTT>) {
			($c, $unic) = split /\t/, $_;
			$orig =~ s/$c/$unic/g;
			$iw =~ s/$c/$unic/g;
		}
		close(TTT);
	}

	$orig =~ s/ /_/g;
	$iw =~ s/ /_/g;
	print "--------PT: $orig\n--------EN: $iw\n";
	#$msg = `echo '[[$orig]]' > massive.tmp`;
	$msg = `echo -e "$orig\t$iw" >> massive.lista.culturas.tmp`;
	$msg = `python interwiki.py $orig -hint:en:$iw -autonomous`;
	print $msg;
#	print "Cmd: python interwiki.py $orig -hint:en:$iw;\n\n";
}

ippar.pl[editar | editar código-fonte]

#!/usr/bin/perl

#use utf8;
#binmode STDOUT, :iso-8859-1;

$concelho = $ARGV[0];
#print "Concelho: $concelho\n";
$url = "http://www.ippar.pt/pls/dippar/web_patrim.calc_step?query_str=SELECT+distinct+CODE+FROM+WEB_LISTA_PATRIM+WHERE+CONCELHO%3D%27$concelho%27&upper_lim=0&lower_lim=0&direction=Seguintes&offset=1000";
$ftmp = "/tmp/ippar.html";

#print $url."\n";
$msg = `wget '$url' -O $ftmp -q`;

open (FICH,"<$ftmp") || die "$0: nao abriu ficheiro\n";
$started = 0;
$cel = 1;
print "{| border=\"1\" cellpadding=\"2\"\n!Designações\n!Categoria\n!Tipologia\n![[freguesia|Freguesia]]\n!Grau\n!Ano\n|-\n";
while (<FICH>) {
#	print ".";
	if (/^<td class="texto_vermb" width="10%" height="12" valign="center"> <\/td>$/) {
		$started = 1;
	} elsif ( $started ) {
		if (/^<td class="texto" width="29%" height="12" valign="center">(.*?)(<\/td>)*$/ && ($cel==1)) {
			$cel = 2;
			$nome = $1;
			$nome =~ s/\n//g;
			$nome =~ s/\r//g;
			$nome =~ s/ \/\/ /\]\] \/ \[\[/g;
			$nome =~ s/<br> /\]\] <br \/> \[\[/g;
		} elsif (/^<td class="texto" width="18%" height="12" valign="center">(.*)<\/td>$/ && ($cel==2)) {
			$cel = 4;
			$classif = get_classif($1);
		} elsif (/^<td class="texto" width="25%" height="12" valign="center">(.*) \/ (.*)<br><\/td>$/ && ($cel==4)) {
			$cel = 5;
			$cat1 = $1; 
			$cat2 = $2;
				$cat1 =~ s/Religiosa/religiosa/g; 
				$cat1 =~ s/Civil/civil/g;
				$cat1 =~ s/Militar/militar/g;
			$cat = "[[".$cat1."]]\n|[[".$cat2."]]";
		} elsif (/^<td class="links2" width="10%" height="12" valign="center"><a href="\/pls\/dippar\/pat_pesq_detalhe\?code_pass=(\d+)" class="links2">detalhe<\/a><\/td>$/ && ($cel==5)) {
			$cel = 1;
			&get_detalhes($1);
			&print_info($nome, $classif, $cat, $ano, $freg, $myurl);
		}
	}
}
print "|}\n<small>Legenda: IIM - Imóvel de Interesse Municipal; IIP - Imóvel de Interesse Público; MN - Monumento Nacional; VC - Em vias de classificação; PM - Património Mundial. </small>\n";


sub get_classif {
	$a = $_[0];
	$r = "";
#	print "GET CLASSIF: $a\n";
	if ($a =~ /^Em [Vv]ias de [Cc]lassifica..o/) {
		$a =~ s/Em [Vv]ias de [Cc]lassifica..o//g;
		$r = "VC";
#		print "....\n";
	}
	if ($a =~ /^ \(Homologado - /) {
		$r.="-";
		$a =~ s/^ \(Homologado - //g;
	}
	if ($a =~ /^IIP (Im.vel de )*Interesse P.blico/) {
		$r .= "[[Im%C3%B3vel de Interesse P%C3%BAblico|IIP]]";
	}
	if ($a =~ /^IIM (Im.vel de )*Interesse Municipal/) {
		$r .= "[[Im%C3%B3vel de Interesse Municipal|IIM]]";
	}
	if ($a =~ /^MN Monumento Nacional/) {
		$r .= "[[Monumento Nacional|MN]]";
	}
	if ($a =~ /^PM Patrim%C3%B3nio Mundial/) {
		$r .= "[[Patrim%C3%B3nio Mundial|PM]]";
	}
	return $r;
}


sub get_detalhes {
	$u = "http://www.ippar.pt/pls/dippar/pat_pesq_detalhe?code_pass=".$_[0];
	$msg = `wget $u -O /tmp/ippar-det.html -q`;
	$ano = ""; $freg = "";
	open (FFF,"</tmp/ippar-det.html") || return;
	while (<FFF>) {
		if ( /^<tr><td class="texto_verm" width="119" valign="top">Decreto<\/td><td class="texto" width="411" valign="top">.*?(\d+)<\/td><\/tr>$/ ) {
			$ano = "[[$1]]";
		} elsif ( /^<tr><td class="texto_verm" width="119" valign="top">Divis.o Administrativa<\/td><td class="texto" width="411" valign="top">(.+?) \/ .*?<\/td><\/tr>$/ ) {
			$freg = "[[$1]]";
		}
	}
#	print $u."\n";
	$myurl = $u;
}

sub print_info {
	print "| [".$_[5]."] [[".$_[0]."]]\n";
	print "|".$_[2]."\n";
	print "|".$_[4]."\n";
	print "|".$_[1]."\n";
	print "|".$_[3]."\n";
	print "|-\n";
}

resolve_redirects.pl[editar | editar código-fonte]

Nota: Este scripts usa os resultados de Wikipedia:Estaleiro/Estatísticas#Artigos com interlinks para redirects (wp-redirs.txt)

#!/usr/bin/perl

open(FICH, "<cmds/wp-redirs.txt") || die "$0: shit\n";

while (<FICH>) {
	if (/^(.*?)\t(.*)$/) {
		print "redir: $1 ------------  target: $2\n";
		$destino = `echo "$2" | iconv -t iso-8859-1 -f utf-8` ;
		system("python solve_disambiguation.py $1 '-pos:$destino' -just -always:0");
	}
}

Comunas da Itália[editar | editar código-fonte]

comuni.pl[editar | editar código-fonte]

Ver artigo principal: [[1]]
#!/usr/bin/perl

#getit.pl 'comuna' 'dx' 'regiao' 'dx' 'provincia'
#getit.pl Acciano do Abruzzo do Aquila

$regiao=$ARGV[4];
$regiaotxt=$ARGV[3];
$provincia = $ARGV[2];
$provinciatxt = $ARGV[1];
$comuna=$ARGV[0];



#binmode(STDOUT, ":utf8");

$msg = `wget http://it.wikipedia.org/wiki/Speciale:Export --post-data="curonly=checked&action=submit&pages=$comuna" -q -O -`;

@linhas = split /\n/,$msg;
foreach $linha (@linhas) {
  if ( $linha =~ /^\s*(.+?)\s*\<\!\-\-scrivere qu.+ il nome del comune\-\-\>/ ) {
    $d_nome = $1;
  } elsif ( $linha =~ /^\s*(.+?)\s*<!--scrivere la latitudine del capoluogo del comune - non scrivere Nord che viene messo automaticamente-->/ ) {
    $d_latitude = $1;
  } elsif ( $linha =~ /^\s*(.+?)\s*<!--scrivere la longitudine del capoluogo del comune - non scrivere Est che viene messo automaticamente-->/ ) {
    $d_longitude = $1;
  } elsif ( $linha =~ /^\*s*(.+?)\s*<!--scrivere l\'altezza del capoluogo del comune in metri - non scrivere la m finale che viene messa automaticamente-->/ ) {
    $d_altitude = $1;
  } elsif ( $linha =~ /^\s*(.+?)\s*<!--scrivere la superficie del comune \(in km2\) - di solito con due decimali - - non scrivere km2 che viene messo automaticamente-->/ ) {
    $d_area = $1;
    $d_area =~ s/\s*superficie\s*=\s*//g;
  } elsif ( $linha =~ /^\s*(.+?)\s*<!--scrivere la popolazione totale del comune - col punto separatore delle migliaia - eventualmente aggiungere <small>2001<\/small>-->/ ) {
    $d_populacao = $1;
  } elsif ( $linha =~ /^\s*(.+?)\s*<!--scrivere la densit.+?  di popolazione del comune - con due decimali-->/ ) {
    $d_densidade = $1;
  } elsif ( $linha =~ /^\s*(.+?)\s*<!--Comuni confinanti anche di altre province - se non ci sono lasciare lo spazio &nbsp; - non scrivere nella riga sopra, ma solo in questa - nomi esatti con doppie parentesi quadre \(sempre\) - separati da virgola e spazio - non usare <br> va a capo automaticamente-->/ ) {
    $d_adjacentes = $1;
  } elsif ( $linha =~ /^\s*(.+?)\s*<!--codice di avviamento postale del comune - anche pi.+ di uno-->/ ) {
    $d_cap = $1;
  } elsif ( $linha =~ /^\s*(.+?)\s*<!--prefisso telefonico del comune - anche pi.+ di uno-->/ ) {
    $d_pref_tel = $1;
  } elsif ( $linha =~ /^\s*(.+?)\s*<!--codice istat del comune - 6 cifre con 0 iniziale-->/ ) {
    $d_istat = $1;
  } elsif ( $linha =~ /^\s*(.+?)\s*<!--iniziale del codice fiscale-->/ ) {
    $d_fiscal = $1;
    $d_fiscal =~ s/\s*fiscale\s*=\s*//g;
  } elsif ( $linha =~ /^\s*(.+?)\s*<!--nome degli abitanti-->/ ) {
    $d_habitantes = $1;
  } elsif ( $linha =~ /^\s*(.+?)\s*<!--nome del Santo Patrono del Comune-->/ ) {
    $d_nomepatrono = $1;
  } elsif ( $linha =~ /^\s*(.+?)\s*<!--ricorrenza del Santo Patrono - giorno festivo per il Comune - nella forma \[\[7 maggio\]\] con doppie parentesi quadre-->/ ) {
    $d_datapatrono = $1;
  } elsif ( $linha =~ /^\s*(.+?)\s*<!--sito internet ufficiale del comune - con singole parentesi quadre-->/ ) {
    $d_site = $1;
  }
}

print "{{Info/Comuna da Itália/temp|\n";
print "|regiao_art    = ".$ARGV[1]."\n";
print "|regiao        = ".$ARGV[2]."\n";
print "|provincia_art = ".$ARGV[3]."\n";
print "|provincia     = ".$ARGV[4]."\n";
print "|nome          = $d_nome\n";
print "|latitude      = $d_latitude\n";
print "|longitude     = $d_longitude\n";
print "|altitude      = $d_altitude\n";
print "|area          = $d_area\n";
print "|populacao     = $d_populacao\n";
print "|densidade     = $d_densidade\n";
print "|adjacentes    = $d_adjacentes\n";
print "|cap           = $d_cap\n";
print "|pref_tel      = $d_pref_tel\n";
print "|istat         = $d_istat\n";
print "|fical         = $d_fiscal\n";
print "|habitantes    = $d_habitantes\n";
print "|nomepatrono   = $d_nomepatrono\n";
print "|datapatrono   = $d_dataptrono\n";
if ( $d_site != "" ) {
  print "|site          = $d_site\n";
} else {
  print "|site          = \n";
}
print "}}\n";

print "{{esboço-geoit}}\n\n";

print "[[Categoria:Comunas d$provinciatxt $provincia]]\n";
print "[[Categoria:Comunas d$regiaotxt $regiao]]\n\n";

print "[[it:".$ARGV[0]."]]\n";

comuni.php[editar | editar código-fonte]

<html>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-88591-1">

<body>
<form action="comuni.php" method="post">
Procurar sobre <input type="text" name="comuna" value="<?php echo $_POST["comuna"]; ?>">
regiao d<input type="text" name="regiaotxt" value="<?php echo $_POST["regiaotxt"]; ?>"> <input type="text" name="regiao" value="<?php echo $_POST["regiao"]; ?>">
, provincia d<input type="text" name="provinciatxt" value="<?php echo $_POST["provinciatxt"]; ?>"> <input type="text" name="provincia" value="<?php echo $_POST["provincia"]; ?>">.

<br>
<?php 
if ( $_POST["comuna"] != "" ) {
   $txt = `./comuni.pl "$_POST[comuna]" "$_POST[regiaotxt]" "$_POST[regiao]" "$_POST[provinciatxt]" "$_POST[provincia]"`; 
//echo "pois";
   }
   
?>
<br>


<textarea name="txt" cols="100" rows=10>
<?php echo $txt; ?>
</textarea>
<input type="submit">
</form>

<?php
 if ( $_POST["comuna"] != "" ) { 
?>
Cat:<a href="http://pt.wikipedia.org/wiki/Categoria:Comunas d<?php echo $_POST["provinciatxt"]; ?> <?php echo $_POST["provincia"]; ?>">Provincia</a><br>


Cat:<a href="http://pt.wikipedia.org/wiki/Categoria:Comunas d<?php echo $_POST["regiaotxt"]; ?> <?php echo $_POST["regiao"]; ?>">Regiao</a><br>

<!-- it:<a href="http://it.wikipedia.org/wiki/<?php echo $_POST["comuna"] ?>"><?php echo $_POST["comuna"] ?></a><br><br> -->
<?php 
} 
?>
pt: <a href="http://pt.wikipedia.org/w/index.php?title=<?php echo $_POST["comuna"]; ?>&action=edit">http://pt.wikipedia.org/w/index.php?title=<?php echo $_POST["comuna"]; ?>&action=edit</a><br>
it: <a href="http://it.wikipedia.org/w/index.php?title=<?php echo $_POST["comuna"]; ?>&action=edit">http://it.wikipedia.org/w/index.php?title=<?php echo $_POST["comuna"]; ?>&action=edit</a>

<script language="javascript">
//ref1 = window.open('http://pt.wikipedia.org/w/index.php?title=<?php echo $_POST["comuna"]; ?>&action=edit');
//ref2 = window.open('http://it.wikipedia.org/w/index.php?title=<?php echo $_POST["comuna"]; ?>&action=edit');
</script>;

</body>
</html>

comuni2.php[editar | editar código-fonte]

<html>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-88591-1">

<body>

<?php 
if ( isset($_POST["list"]) && ($_POST["list"] != "") ) {
  $arr = preg_split ('/\n/', $_POST["list"],  -1, PREG_SPLIT_NO_EMPTY);
  foreach ($arr  as $comune) {
    if ( preg_match("/^    \* /", $comune) ) {
        $comune = preg_replace("/^    \* /", "", $comune);
        print "<li><a href=\"http://republico.estv.ipv.pt/~nmct/comuni-it/comuni3.php?_comuna=$comune&_regiaotxt=".$_POST["regiaotxt"]."&_regiao=".$_POST["regiao"]."&_provinciatxt=".$_POST["provinciatxt"]."&_provincia=".$_POST["provincia"]."&_token=".$_POST["token"]."\">$comune</a>\n";
    }
  }
} else {
?>
<form name="lista" action="comuni2.php" method="POST">
Links para regiao d<input type="text" name="regiaotxt" value="<?php echo $_POST["regiaotxt"]; ?>"> <input type="text" name="regiao" value="<?php echo $_POST["regiao"]; ?>">
, provincia d<input type="text" name="provinciatxt" value="<?php echo $_POST["provinciatxt"]; ?>"> <input type="text" name="provincia" value="<?php echo $_POST["provincia"]; ?>">.

<p>
Token: <input type="text" name="token">
<p>
Lista (comuna por linha):<br>
<textarea name="list" cols="100" rows=10>
</textarea>
<input type="submit">
</form>

[[<a href="http://pt.wikipedia.org/wiki/Categoria d<?php echo $_POST[provinciatxt]." ".$_POST[provincia]; ?>">Categoria!</a>]]

<?php 
}
?>

</body>
</html>

comuni3.php[editar | editar código-fonte]

<?php
  header('Content-Type: text/html; charset=utf-8');
?>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-88591-1">

<body>
<?php
if ( $_GET["skip"] != "y" ) {
  $regiao = `echo -n "$_GET[_regiao]" | iconv -t utf-8 -f iso-8859-1`;
  $provincia = `echo -n "$_GET[_provincia]" | iconv -t utf-8 -f iso-8859-1`;
} else {
  $regiao = $_GET[_regiao];
  $provincia = $_GET[_provincia];
}

?>
<form name="frm_refresh" action="comuni3.php" method="get">
Procurar sobre <input type="text" name="_comuna" value="<?php echo $_GET["_comuna"]; ?>">
regiao d<input type="text" name="_regiaotxt" value="<?php echo $_GET["_regiaotxt"]; ?>"> <input type="text" name="_regiao" value="<?php echo $regiao; ?>">
, provincia d<input type="text" name="_provinciatxt" value="<?php echo $_GET["_provinciatxt"]; ?>"> <input type="text" name="_provincia" value="<?php echo $provincia; ?>">.
<input type="hidden" name="skip" value="y">
<input type="submit">
</form>
<br>
<?php 
if ( $_GET["_comuna"] != "" ) {
   $txt = `./comuni.pl "$_GET[_comuna]" "$_GET[_regiaotxt]" "$regiao" "$_GET[_provinciatxt]" "$provincia"`; 
//   echo "shit - $regiao - shit";
   }
   
?>
<br>

<h3><strike>Amigos, ja' nao e' necessario fazer copy&paste. Usem os botoes como na WP</strike></h3>


Nao usem! BUG: Se o artigo ja' existir, ficara' reescrito... esta' quase perfeito este script :)


<form name="frm_send" action="http://pt.wikipedia.org/w/index.php?title=<?php echo $_GET["_comuna"]; ?>&action=submit" method="post">
<textarea name="wpTextbox1" cols="100" rows=10>
<?php echo $txt; ?>
</textarea>
<input tabindex='3' type='checkbox' value='1' name='wpMinoredit' checked='checked' accesskey='i' id='wpMinoredit' />
w: <input tabindex='4' type='checkbox' name='wpWatchthis' accesskey='w' id='wpWatchthis' value='1' checked='checked' />
<input tabindex='5' id='wpSave' type='submit' value="Salvar página" name="wpSave" accesskey="s" title="Salvar as alterações [alt-s]."/>
<input tabindex='6' id='wpPreview' type='submit' value="Mostrar previsão" name="wpPreview" accesskey="p" title="Prever as alterações [alt-p]. Por favor, usar antes de salvar!"/>
<input type='hidden' value="" name="wpSection" />
<input type='hidden' value="20060506021318" name="wpEdittime" />

<?php
if ( $_GET[_token] != "" ) {
  $token = $_GET[_token];
} else {
  $token = "989482b0a3d2378000610f1a12199a25";
} 
?>
<input type='hidden' value="<?php echo $token; ?>" name="wpEditToken" />
</form>

<?php
 if ( $_GET["_comuna"] != "" ) { 
?>
Cat:<a href="http://pt.wikipedia.org/wiki/Categoria:Comunas d<?php echo $_GET["_provinciatxt"]; ?> <?php echo $provincia; ?>">Provincia</a><br>


Cat:<a href="http://pt.wikipedia.org/wiki/Categoria:Comunas d<?php echo $_GET["_regiaotxt"]; ?> <?php echo $regiao; ?>">Regiao</a><br>

<!-- it:<a href="http://it.wikipedia.org/wiki/<?php echo $_GET["_comuna"] ?>"><?php echo $_GET["_comuna"] ?></a><br><br> -->
<?php 
} 
?>
pt: <a href="http://pt.wikipedia.org/w/index.php?title=<?php echo $_GET["_comuna"]; ?>&action=edit">http://pt.wikipedia.org/w/index.php?title=<?php echo $_GET["comuna"]; ?>&action=edit</a><br>
it: <a href="http://it.wikipedia.org/w/index.php?title=<?php echo $_GET["_comuna"]; ?>&action=edit">http://it.wikipedia.org/w/index.php?title=<?php echo $_GET["comuna"]; ?>&action=edit</a>

<script language="javascript">
//ref1 = window.open('http://pt.wikipedia.org/w/index.php?title=<?php echo $_GET["_comuna"]; ?>&action=edit');
//ref2 = window.open('http://it.wikipedia.org/w/index.php?title=<?php echo $_GET["_comuna"]; ?>&action=edit');
</script>;

</body>
</html>

Comunas da Suíça[editar | editar código-fonte]

Comunas da França[editar | editar código-fonte]

Cidades do Japão[editar | editar código-fonte]

jp.pl[editar | editar código-fonte]

#!/usr/bin/perl

#getit.pl 'comuna' 'dx' 'regiao' 'dx' 'provincia'
#getit.pl Acciano do Abruzzo do Aquila

$regiao=$ARGV[1];
$cidadept=$ARGV[2];
$comuna=$ARGV[0];



#binmode(STDOUT, ":utf8");

$msg = `wget http://en.wikipedia.org/wiki/Special:Export --post-data="curonly=checked&action=submit&pages=$comuna" -q -O -`;

@linhas = split /\n/,$msg;
foreach $linha (@linhas) {
  if ( $linha =~ /\'\'\'.*?\'\'\' \((.*?)\; (\-\w+).*\) is / ) {
    $d_nomejp = $1;
    $d_transc = $2;
  }
  if ( $linha =~ /As of \[*(\d+)\]*\, the city/ ) {
    $d_datageo = $1;
  }
  if ( $linha =~ /estimated \[*population\]* of ([\d\.\,]+) and \w+ \[\[population density\|density\]\] of ([\d+\.\,]+) persons per/ ) {
    $d_populacao = $1;
    $d_densidade = $2;
  }
  if ( $linha =~ /The total area is (.*?) km/ ) {
    $d_area = $1;
  }
  if ( $linha =~ /The city was founded on \[\[(\w+ \d+)\]\], (\[\[\d+\]\])/ ) {
    $dia_mes = data_en2pt ($1);
    $d_estatuto = "[[$dia_mes]] de $2";
  } elsif ( $linha =~ /^\*\s+\[(http\:.*?)\s.*\]/ ) {
    $d_site = $1;
  }
}

print "{{Cidade do Japão/temp|\n";
print "|província     = ".$ARGV[1]."\n";
print "|nomept        = $cidadept\n";
print "|nomejp        = $d_nomejp\n";
print "|transcrição   = $d_transc\n";
print "|datageo       = $d_datageo\n";
print "|população     = $d_populacao\n";
print "|densidade     = $d_densidade\n";
print "|área          = $d_area\n";
print "|estatuto      = $d_estatuto\n";
print "|site          = $d_site\n";
print "|extra         = \n\n";
print "}}\n\n";

#print "{{Japão/Prefeitura de ".$regiao."}}\n\n";

print "{{esboço-geojp}}\n\n";

print "[[Categoria:Cidades do Japão]]\n";
print "[[Categoria:Cidades da províndia de $regiao]]\n\n";

print "[[en:".$ARGV[0]."]]\n";


sub data_en2pt {
  if ( $_[0] =~ /\[*(\w+) (\d+)\]*/ ) {
    $mes = $1;
    $dia = $2;
    if ( $mes eq "January" ) { $mes = "Janeiro"; }
    elsif ( $mes eq "February" ) { $mes = "Fevereiro"; }
    elsif ( $mes eq "March" ) { $mes = "Março"; }
    elsif ( $mes eq "April" ) { $mes = "Abril"; }
    elsif ( $mes eq "May" ) { $mes = "Maio"; }
    elsif ( $mes eq "June" ) { $mes = "Junho"; }
    elsif ( $mes eq "July" ) { $mes = "Julho"; }
    elsif ( $mes eq "August" ) { $mes = "Agosto"; }
    elsif ( $mes eq "September" ) { $mes = "Setembro"; }
    elsif ( $mes eq "October" ) { $mes = "Outubro"; }
    elsif ( $mes eq "November" ) { $mes = "Novembro"; }
    elsif ( $mes eq "December" ) { $mes = "Dezembro"; }
  }
  return "$dia de $mes";
  
}

jp.php[editar | editar código-fonte]

<html>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-88591-1">

<body>

<?php 
if ( isset($_POST["list"]) && ($_POST["list"] != "") ) {
  $arr = preg_split ('/\n/', $_POST["list"],  -1, PREG_SPLIT_NO_EMPTY);
  foreach ($arr  as $comune) {
    if ( preg_match("/^    \* /", $comune) ) {
        $comune = preg_replace("/^    \* /", "", $comune);
        print "<li><a href=\"http://republico.estv.ipv.pt/~nmct/cidades-jp/jp2.php?_comuna=$comune&_regiao=".$_POST["regiao"]."&_provinciatxt=".$_POST["provinciatxt"]."&_provincia=".$_POST["provincia"]."&_token=".$_POST["token"]."\">$comune</a>\n";
    }
  }

?>
<P>
[[<a href="http://pt.wikipedia.org/wiki/Categoria:Cidades da prefeitura de <?php echo $regiao; ?>">Categoria:Cidades da prefeitura de <?php echo $regiao; ?></a>]]
<?php
} else {
?>
<form name="lista" action="jp.php" method="POST">
Links para a prefeitura <input type="text" name="regiao" value="<?php echo $_POST["regiao"]; ?>">

<p>
Token: <input type="text" name="token">
<p>
Lista (comuna por linha):<br>
<textarea name="list" cols="100" rows=10>
</textarea>
<input type="submit">
</form>


<?php 
}
?>

</body>
</html>

jp2.php[editar | editar código-fonte]

<?php
  header('Content-Type: text/html; charset=utf-8');
?>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-88591-1">

<body>
<?php
if ( $_GET["skip"] != "y" ) {
  $regiao = `echo -n "$_GET[_regiao]" | iconv -t utf-8 -f iso-8859-1`;
} else {
  $regiao = $_GET[_regiao];
}
$cidadept = preg_replace("/(.*?)\, .*/", "$1", $_GET["_comuna"]);

//print "=== $cidadept ===\n";
?>
<form name="frm_refresh" action="comuni3.php" method="get">
Cidade <input type="text" name="_comuna" value="<?php echo $_GET["_comuna"]; ?>">
prefeitura de <input type="text" name="_regiao" value="<?php echo $regiao; ?>">
<input type="hidden" name="skip" value="y">
<input type="submit">
</form>
<br>
<?php 
if ( $_GET["_comuna"] != "" ) {
   $txt = `./jp.pl "$_GET[_comuna]" "$regiao" "$cidadept"`; 
//   echo "shit - $regiao - shit";
   }   
?>



Nao usem! BUG: Se o artigo ja' existir, ficara' reescrito... esta' quase perfeito este script :)


<form name="frm_send" action="http://pt.wikipedia.org/w/index.php?title=<?php echo $cidadept; ?>&action=submit" method="post">
<textarea name="wpTextbox1" cols="100" rows=10>
<?php echo $txt; ?>
</textarea>
<input tabindex='3' type='checkbox' value='1' name='wpMinoredit' checked='checked' accesskey='i' id='wpMinoredit' />
w: <input tabindex='4' type='checkbox' name='wpWatchthis' accesskey='w' id='wpWatchthis' value='1' checked='checked' />
<input tabindex='5' id='wpSave' type='submit' value="Salvar página" name="wpSave" accesskey="s" title="Salvar as alterações [alt-s]."/>
<input tabindex='6' id='wpPreview' type='submit' value="Mostrar previsão" name="wpPreview" accesskey="p" title="Prever as alterações [alt-p]. Por favor, usar antes de salvar!"/>
<input type='hidden' value="" name="wpSection" />
<input type='hidden' value="20060506021318" name="wpEdittime" />

<?php
if ( $_GET[_token] != "" ) {
  $token = $_GET[_token];
} else {
  $token = "989482b0a3d2378000610f1a12199a25";
} 
?>
<input type='hidden' value="<?php echo $token; ?>" name="wpEditToken" />
</form>

<?php
 if ( $_GET["_comuna"] != "" ) { 
?>

Cat:<a href="http://pt.wikipedia.org/wiki/Categoria:Cidades da prefeitura de <?php echo $regiao; ?>">Categoria:Cidades da prefeitura de <?php echo $regiao; ?></a><br>
<p>

<?php 
} 
?>
pt: <a href="http://pt.wikipedia.org/w/index.php?title=<?php echo $cidadept; ?>&action=edit">http://pt.wikipedia.org/w/index.php?title=<?php echo $cidadept; ?>&action=edit</a><br>

en: <a href="http://en.wikipedia.org/w/index.php?title=<?php echo $_GET["_comuna"]; ?>&action=edit">http://en.wikipedia.org/w/index.php?title=<?php echo $_GET["_comuna"]; ?>&action=edit</a>

</body>
</html>

Municípios da Espanha[editar | editar código-fonte]

mun_es.php[editar | editar código-fonte]

<?php
#  header('Content-Type: text/html; charset=utf-8');
$limit = $_GET['limit'];
$page = $_GET['page'];
if ( !($_GET['limit'] != "") ) { $limit = 10; }
if ( !($_GET['page'] != "") ) { $page = 0; }
?>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-88591-1">

<body>
[ <a href="http://republico.estv.ipv.pt/~nmct/espanha/mun_es.php?<?php echo "prov=".$_GET['prov']."&limit=".$limit."&page=".($page+1); ?>">>></a> ]
<p>
<hr>

<i>
<?php 
$q = "SELECT m.*, p.de, p.nome, p.alias, r.de, r.nome, r.alias, p.also_reg ".
"FROM spainmun m, spainprov p, spainreg r ".
"WHERE m.cod_prov = p.cod_prov ".
"  AND p.cod_reg = r.cod ".
"  AND p.nome LIKE '".$_GET['prov']."' ".
"LIMIT ".($limit*$page).", ".$limit;

$token = "";

mysql_select_db("onun", mysql_pconnect("localhost","------","------"));

$res = mysql_query($q);

$iform = 0;

#while ( ($row = mysql_fetch_row($res)) and (!$iform) ) {
while ( $row = mysql_fetch_row($res) ) {
  $title = $row[0];
  $txtarea = $_[2];
  $j = $_[3];
  print "<form name=\"frm_send\" action=\"http://pt.wikipedia.org/w/index.php?title=".$row[0]."&action=submit\" method=\"post\" accept-charset=\"utf-8\">\n";
  $area = str_replace(".", ",", sprintf("%2.2f", $row[6]));  
  $pops = preg_split("/\t/", $row[4]);
  $densidade = str_replace(".", ",", sprintf("%2.2f", $pops[0]/$row[6]));
  $lat = ""; $long = "";
  if ( preg_match("/(\d+)\.(\d+)\s*(\w)/", $row[9], $ar)  ) {
    $latgc = sprintf("%02d",$ar[1])."_".sprintf("%02d",$ar[2])."_00_".$ar[3]; 
    $lat = sprintf("%02d",$ar[1])."° ".sprintf("%02d",$ar[2])."' ".$ar[3];
  }
  $l = "W";
  if ( preg_match("/(\d+)\.(\d+)\s*(\w)/", $row[8], $ar) ) {
    $longgc = sprintf("%02d",$ar[1])."_".sprintf("%02d",$ar[2])."_00_W"; 
    $long = sprintf("%02d",$ar[1])."° ".sprintf("%02d",$ar[2])."' ".$ar[3];
  }
  
?>
  <textarea name="wpTextbox1" cols="1" rows=1>
<?php
  if ( $lat != "" ) {
    print "{{geocoordenadas|".$latgc."_".$longgc."|$lat $long}}\n";
  }
?>
{{Info/Município da Espanha|
|nome      = <?php echo $row[0]."\n"; ?>
|nome_es   = <?php echo $row[0]."\n"; ?>
|num       = <?php printf("%03d\n", $row[3]); ?>
|província = [[Província <?php echo $row[10]." ".$row[11]."|".$row[11]; ?>]] <!-- <?php printf("(%02d)", $row[1]); ?> -->
|comun_aut = [[<?php echo $row[14]; ?>]] <!-- <?php printf("(%02d)", $row[2]); ?> -->
|imagem    = <!-- inserir apenas nome da imagem -->
|bandeira  = <!-- inserir apenas nome da imagem -->
|brasão    = <!-- inserir apenas nome da imagem -->
|mapa      = <!-- inserir apenas nome da imagem -->
|área      = <?php echo $area."\n"; ?>
|altitude  = 
|população = <?php echo $pops[0]."\n"; ?>
|censo     = 2004
|densidade = <?php echo $densidade."\n"; ?>
|latitude  = <?php echo $lat."\n"; ?>
|longitude = <?php echo $long."\n"; ?>
|website   = <!-- www.qualquer coisa (sem http://) -->
}}
'''<?php echo $row[0]; ?>''' é um [[Lista de municípios da Espanha|município]] da [[Espanha]] na [[Províncias da Espanha|província]] <?php echo $row[10]." [[Província ".$row[10]." ".$row[11]."|".$row[11]."]]"; ?>, [[Comunidades autónomas da Espanha|comunidade autónoma]] <?php echo $row[13]." [[".$row[14]."]]"; ?>, de área <?php echo $area; ?> [[quilómetro quadrado|km&sup2]] com população de <?php echo $pops[0]; ?> habitantes ([[2004]]) e [[densidade populacional]] de <?php echo $densidade; ?> hab/km².

==Demografia==
{| {{prettytable1|center}}
! colspan="4" | Variação [[demografia|demográfica]] do município entre [[1991]] e [[2004]]
|- bgcolor="#C0C0C0"
| align="center" | [[2004]] 
| align="center" | [[2001]] 
| align="center" | [[1996]] 
| align="center" | [[1991]]
|-
| align="center" | <?php echo $pops[0]."\n| align=\"center\" | ".$pops[1]."\n| align=\"center\" | ".$pops[2]."\n| align=\"center\" | ".$pops[3]."\n"; ?>
|}


{{Espanha/<?php echo $row[14]."/".$row[11]; ?>}}


{{esboço-municípios-es}}

<?php 
$catnome = $row[0]; 
if ( $row[5] != "" ) { $catnome = $row[5]; }
?>
[[Categoria:Municípios da Espanha|<?php echo $catnome; ?>]]
[[Categoria:Municípios <?php echo $row[13]." ".$row[14]."|".$catnome; ?>]]
<?php if (!$row[16]) { ?>
[[Categoria:Municípios da província <?php echo $row[10]." ".$row[11]."|".$catnome; ?>]]
<?php } ?>

[[es:<?php echo $row[0]; ?>]]
[[it:<?php echo $row[0]; ?>]]
</textarea>
<?php
  print "<input tabindex='4' type='checkbox' name='wpWatchthis' accesskey='w' id='wpWatchthis' value='1' checked='checked' />\n";
  print "<input tabindex='2' type='hidden' value=\"Artigo assistido por bot: [[Wikipedia:Projetos/Cidades do Mundo|WikiProjecto:Cidades do Mundo]]\" name=\"wpSummary\" maxlength='200' size='60' />";
  print "<input tabindex='5' id='wpSave' type='submit' value=\"$title\" name=\"wpSave\" accesskey=\"s\" title=\"Salvar as alterações\" onclick=\"document.forms[$iform].target='_new';\">\n";
  print "</form>";
  print "$iform: [[<a href=\"http://pt.wikipedia.org/w/index.php?title=$title&action=edit\">$title</a>]]";
  $iform++;
}

?>
</body>
</html>

Adaptação para províncias = regiões[editar | editar código-fonte]

<?php
#  header('Content-Type: text/html; charset=utf-8');
$limit = $_GET['limit'];
$page = $_GET['page'];
if ( !($_GET['limit'] != "") ) { $limit = 10; }
if ( !($_GET['page'] != "") ) { $page = 0; }
?>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-88591-1">

<body>
[ <a href="http://republico.estv.ipv.pt/~nmct/espanha/mun_es1.php?<?php echo "prov=".$_GET['prov']."&limit=".$limit."&page=".($page+1); ?>">>></a> ]
<p>
<hr>

<i>
<?php 
$q = "SELECT m.*, p.de, p.nome, p.alias, r.de, r.nome, r.alias, p.also_reg ".
"FROM spainmun m, spainprov p, spainreg r ".
"WHERE m.cod_prov = p.cod_prov ".
"  AND p.cod_reg = r.cod ".
"  AND p.nome LIKE '".$_GET['prov']."' ".
"LIMIT ".($limit*$page).", ".$limit;

$token = "";

mysql_select_db("onun", mysql_pconnect("localhost","------","------"));

$res = mysql_query($q);

$iform = 0;

#while ( ($row = mysql_fetch_row($res)) and (!$iform) ) {
while ( $row = mysql_fetch_row($res) ) {
  $title = $row[0];
  $txtarea = $_[2];
  $j = $_[3];
  print "<form name=\"frm_send\" action=\"http://pt.wikipedia.org/w/index.php?title=".$row[0]."&action=submit\" method=\"post\" accept-charset=\"utf-8\">\n";
  $area = str_replace(".", ",", sprintf("%2.2f", $row[6]));  
  $pops = preg_split("/\t/", $row[4]);
  $densidade = str_replace(".", ",", sprintf("%2.2f", $pops[0]/$row[6]));
  $lat = ""; $long = "";
  if ( preg_match("/(\d+)\.(\d+)\s*(\w)/", $row[9], $ar)  ) {
    $latgc = sprintf("%02d",$ar[1])."_".sprintf("%02d",$ar[2])."_00_".$ar[3]; 
    $lat = sprintf("%02d",$ar[1])."° ".sprintf("%02d",$ar[2])."' ".$ar[3];
  }
  $l = "W";
  if ( preg_match("/(\d+)\.(\d+)\s*(\w)/", $row[8], $ar) ) {
    $longgc = sprintf("%02d",$ar[1])."_".sprintf("%02d",$ar[2])."_00_W"; 
    $long = sprintf("%02d",$ar[1])."° ".sprintf("%02d",$ar[2])."' ".$ar[3];
  }
  
?>
  <textarea name="wpTextbox1" cols="1" rows=1>
<?php
  if ( $lat != "" ) {
    print "{{geocoordenadas|".$latgc."_".$longgc."|$lat $long}}\n";
  }
?>
{{Info/Município da Espanha|
|nome      = <?php echo $row[0]."\n"; ?>
|nome_es   = <?php echo $row[0]."\n"; ?>
|num       = <?php printf("%03d\n", $row[3]); ?>
|província = [[<?php echo $row[15]."|".$row[14]; ?>]] <!-- <?php printf("(%02d)", $row[1]); ?> -->
|comun_aut = [[<?php echo $row[15]."|".$row[14]; ?>]] <!-- <?php printf("(%02d)", $row[2]); ?> -->
|imagem    = <!-- inserir apenas nome da imagem -->
|bandeira  = <!-- inserir apenas nome da imagem -->
|brasão    = <!-- inserir apenas nome da imagem -->
|mapa      = <!-- inserir apenas nome da imagem -->
|área      = <?php echo $area."\n"; ?>
|altitude  = 
|população = <?php echo $pops[0]."\n"; ?>
|censo     = 2004
|densidade = <?php echo $densidade."\n"; ?>
|latitude  = <?php echo $lat."\n"; ?>
|longitude = <?php echo $long."\n"; ?>
|website   = <!-- www.qualquer coisa (sem http://) -->
}}
'''<?php echo $row[0]; ?>''' é um [[Lista de municípios da Espanha|município]] da [[Espanha]] 
na [[Províncias da Espanha|província]] e [[Comunidades autónomas da Espanha|comunidade autónoma]] <?php echo $row[13]." [[".$row[15]."|".$row[14]."]]"; ?>, de área <?php echo $area; ?> [[quilómetro quadrado|km&sup2]] com população de <?php echo $pops[0]; ?> habitantes ([[2004]]) e [[densidade populacional]] de <?php echo $densidade; ?> hab/km².

==Demografia==
{| {{prettytable1|center}}
! colspan="4" | Variação [[demografia|demográfica]] do município entre [[1991]] e [[2004]]
|- bgcolor="#C0C0C0"
| align="center" | [[2004]] 
| align="center" | [[2001]] 
| align="center" | [[1996]] 
| align="center" | [[1991]]
|-
| align="center" | <?php echo $pops[0]."\n| align=\"center\" | ".$pops[1]."\n| align=\"center\" | ".$pops[2]."\n| align=\"center\" | ".$pops[3]."\n"; ?>
|}


{{Espanha/<?php echo $row[14]; ?>}}


{{esboço-municípios-es}}

<?php 
$catnome = $row[0]; 
if ( $row[5] != "" ) { $catnome = $row[5]; }
?>
[[Categoria:Municípios da Espanha|<?php echo $catnome; ?>]]
[[Categoria:Municípios <?php echo $row[13]." ".$row[14]."|".$catnome; ?>]]
<?php if (!$row[16]) { ?>
[[Categoria:Municípios da província <?php echo $row[10]." ".$row[11]."|".$catnome; ?>]]
<?php } ?>

[[es:<?php echo $row[0]; ?>]]
[[it:<?php echo $row[0]; ?>]]
</textarea>
<?php
  print "<input tabindex='4' type='checkbox' name='wpWatchthis' accesskey='w' id='wpWatchthis' value='1' checked='checked' />\n";
  print "<input tabindex='2' type='hidden' value=\"Artigo assistido por bot: [[Wikipedia:Projetos/Cidades do Mundo|WikiProjecto:Cidades do Mundo]]\" name=\"wpSummary\" maxlength='200' size='60' />";
  print "<input tabindex='5' id='wpSave' type='submit' value=\"$title\" name=\"wpSave\" accesskey=\"s\" title=\"Salvar as alterações\" onclick=\"document.forms[$iform].target='_new';\">\n";
  print "</form>";
  print "$iform: [[<a href=\"http://pt.wikipedia.org/w/index.php?title=$title&action=edit\">$title</a>]]";
  $iform++;
}

=== espanha.pl ===
Script para adicionar as coordenadas à BD

<pre>
#!/usr/bin/perl

use DBI;

$dbuser = '-----';
$dbpwd = '------';
$database = '------';


$db_handle = DBI->connect("dbi:mysql:database=".$database.";host=localhost;user=".$dbuser.";password=".$dbpwd)
  or die "Couldn't connect to database: $DBI::errstr\n";
    


open (FICH,"<coord.txt") || die "$0: couldnt open file for reading\n";
$contok = 0;
$conterr = 0;
while (<FICH>) {
  if ( /(.+?)\s*\t(.+?)\s\t(.+?)\s\t(.+?)\s*$/ ) {
     ($prov, $mun, $lat, $long) = ($1, $2, $3, $4);
     $alias = $nome;
     if ( $alias =~ /^(.+?)\s+\((.+?)\)$/ ) { $nome = "$2 $1"; } else { $alias = ""; }
     $area =~ s/,/\./g;
     $sql = "UPDATE spainmun SET latitude = '".$lat."', longitude = '".$long."' WHERE nome LIKE '".$mun."' AND cod_prov = ".$prov;
#     print ":$mun ($prov) -- [$lat] -- [$long]\n";
#     print "\t::: $sql\n\n";
     $statement = $db_handle->prepare($sql)
       or die "Couldn't prepare query '$sql': $DBI::errstr\n";

     if ( ! $statement->execute() ) {
#       or die "Couldn't execute query '$sql': $DBI::errstr\n";
        print "WARN: $prov\t$mun\t$lat\t$long\n";
        $conterr++;
     } else { $contok++; }
     
  }
}

print "\n\n$cont records saved.\n";

$db_handle->disconnect();

?> </body> </html>

Prémios Nobel[editar | editar código-fonte]

#!/usr/bin/perl

if (! open(FICH, "<nobelfisica.txt") ) { die "$0: shit\n"; }

sub wp_form {
  $title = $_[0];
  $token = $_[1];
  $txtarea = $_[2];
  $j = $_[3];
  print "<font size=\"1\"><i><a href=\"http://pt.wikipedia.org/w/index.php?title=$title&action=edit\">http://pt.wikipedia.org/w/index.php?title=$title&action=edit</a></font><br>\n";
  print "<form name=\"frm_send\" action=\"http://pt.wikipedia.org/w/index.php?title=".$title."&action=submit\" method=\"post\">\n";
  print "<textarea name=\"wpTextbox1\" cols=\"100\" rows=10>\n";
  print "$txtarea\n";
  print "</textarea>\n";
# new tab(form.submit()): http://kb.mozillazine.org/Firefox_:_FAQs_:_About:config_Entries
  print "<input tabindex='5' id='wpSave' type='submit' value=\"Salvar página\" name=\"wpSave\" accesskey=\"s\" title=\"Salvar as alterações\" onclick=\"document.forms[$j].target='_new';\">\n";
  print "</form>\n<br>\n";
}

$k = 0;
while (<FICH>) {
  if (/(\d+)\t(.+?)\t(.+?)\t(.+?)\t(.+?)\t(.+?)\t(.+?)\t(.+?)\t(.+)/) {
#    print "<a href=\"http://pt.wikipedia.org/w/index.php?title=$2&action=edit\">http://pt.wikipedia.org/w/index.php?title=$2&action=edit</a><br>\n";
    $t = "'''$2''' ([[$4]] de [[$5]] — [[$6]] de [[$7]]), [[Física|físico]] $8. Foi [[Nobel de Física]] em [[$1]] $3\n\n";
    $t .= "=={{Ver também}}==\n";
    $t .= "* [[Nobel de Física]]\n\n";
    $t .= "=={{Links externos}}==\n";
    $t .= "* [http://nobelprize.org/physics/laureates/$1/index.html Biografia] ''em [[língua inglesa|inglês]]''\n\n\n";
    $i = $2;
    $ano = $1;
    $pais = $8;
    ($nome, $apel) = split /\s(\w+)$/, $i; 
    $t .= "{{PremioNobel|área=Física|cat=$apel, $nome|ano=$ano}}\n\n\n";
    $t .= "{{Biografias}}\n\n\n";
    $t .= "{{esboço-física}}\n\n\n";
    
    $pais =~ s/[\[\]]//g;
    
    $t .= "[[Categoria:Físicos $pais]]\n\n";
    $t .= "[[en:$i]]\n";
    
    wp_form "$i", "", $t, $k; 
    $k++;
  }
}

Comunas da Suíça[editar | editar código-fonte]

comunasch.pl[editar | editar código-fonte]

#!/usr/bin/perl

if (! open(LISTA,"<listafinal.txt")) {
  die "$0: tou sem lista\n";
}

use DBI;

$dbuser = 'onun';
$dbpwd = 'seravat';
$database = 'onun';


$db_handle = DBI->connect("dbi:mysql:database=".$database.";host=localhost;user=".$dbuser.";password=".$dbpwd)
  or die "Couldn't connect to database: $DBI::errstr\n";
    
sub charset_conv {
  $txt = $_[0];
  if ( $txt =~ /\'/ ) {
    $msg = `echo "$txt" | iconv -f utf-8 -t iso8859-1 2> /dev/null`;
  } else {
    $msg = `echo '$txt' | iconv -f utf-8 -t iso8859-1 2> /dev/null`;
  }
#  print "::::::::::::::convert \"$txt\" ::::::::::::: \"$msg\"\n"; 
  return $msg;
}    

while (<LISTA>){
  $comuna = $_;
  $comuna =~ s/\r\n$//g;
  $url = "http://it.wikipedia.org/w/index.php?title=".$comuna."&action=raw";
  print "processando: $comuna [$url]\n";
  $out = `wget '$url' -q -O -`;
  @linhas = split /\n/, $out;
#  print $out;
  $d_cantao = ""; $d_densidade = ""; $d_adjacentes = ""; $d_fraccoes = ""; $d_pref_tel = ""; $d_populacao = ""; 
  $d_site = ""; $d_mapa = ""; $d_distrito = ""; $d_lingua = ""; $d_latitude = ""; $d_longitude = ""; $geocoord = "";
  $d_altitude = ""; $d_area = ""; $d_codpostal = ""; $d_bfs = ""; $d_brasao = ""; $d_interwiki = ""; $d_censo = "";
  foreach $linha (@linhas) {
    $linha = &charset_conv($linha);

  #### HACK: don't do this at home!! PerlRE breaks with a strange character    
    if ( $latsok ) {
      $latsok = 0;
      $d_latitude = $linha."' N";
    }
    if ( $longsok ) {
      $longsok = 0;
      $d_longitude = $linha."' E";
    }
    if ( $linha =~ /^latitudine/ ) {
      $latsok = 1;
    }
    if ( $linha =~ /^longitudine/ ) {
      $longsok = 1;
    }

##      if ( $linha =~ /Karte/ ) {
##        print "\n\t\t:::::::::::: KARTE :: $linha \n";
##        $karte = 1;
##      }

    if ( $linha =~ /\s*(.+?)\s*\s*<!--cantone di appartenenza/ ) {
      $d_cantao = $1;
    } elsif ( $linha =~ /^\s*\[\[(.+?)\]\]\s*<!--nome distretto di/ ) {
      $d_distrito = $1; 
      $d_distrito =~ s/ \(distretto.*$//g;
    } elsif ( $linha =~ /^\s*(.*?)\s*<!--scrivere qui il nome dell\'immagine dello stemma\s*/ ) {
      $d_brasao = $1; 
    } elsif ( $linha =~ /^\s*\[\[.*?\|(.+?)\]\]\s*<!-- lingua ufficiale/ ) {
      $d_lingua = $1; 
    } elsif ( $linha =~ /^\s*(\d+.+ \d+).\s*<!--scrivere la latitudine/ ) {
      $d_latitude = $1."' N"; 
    } elsif ( $linha =~ /^\s*(.+?). \s*<!--scrivere la longitudine/ ) {
      $d_longitude = $1."' E";
    } elsif ( $linha =~ /^\s*(.+?)\s*<!--scrivere l\'altezza del / ) {
      $d_altitude = $1; 
    } elsif ( $linha =~ /^\s*(.+?)\s*<!--scrivere la superficie/ ) {
      $d_area = $1; 
    } elsif ( $linha =~ /^\s*(.+?)\s*<!--scrivere la densit.+? di popolazione del comune/ ) {
      $d_densidade = $1; 
    } elsif ( $linha =~ /^\s*(.+?)\s*<!--Comuni confinanti/ ) {
      $d_adjacentes = $1;
      $d_adjacentes =~ s/\[\[(.*?)\|.*?\]\]/[[$1]]/g;
      $d_adjacentes =~ s/\[\[(.*?\w) \(.*?\)\]\]/[[$1]]/g;
    } elsif ( $linha =~ /^\s*(.+?)\s*<!--Eventuali frazioni/ ) {
      $d_fraccoes = $1;
    } elsif ( $linha =~ /^\s*(.+?)\s*<!--codice postale/ ) {
      $d_codpostal = $1;
    } elsif ( $linha =~ /^\s*(.+?)\s*<!--prefisso telefonico del comune/ ) {
      $d_pref_tel = $1;
    } elsif ( $linha =~ /^\s*(.+?)\s*<!--inserire l'anno del censimento/ ) {
      $d_censo = $1;
    } elsif ( $linha =~ /^\s*(.+?)\s*<!--BFS-Nr\./ ) {
      $d_bfs = $1;
    } elsif ( ($linha =~ /^\s*(.+?)\s*<!--scrivere la popolazione totale del comune/) && ($d_populacao == "")) {
      $d_populacao = $1;
    } elsif ( $linha =~ /^\s*(.+?)\s<!--sito internet ufficiale del comune/ ) {
      $d_site = $1;
      $d_site =~ s/http:\/\/(.*?)\/\s*/$1/;
    } elsif ( $linha =~ /^\s*(Karte.*\.png)/ ) {
      $d_mapa = $1;
##    } else {
##      if ( $karte ) {
##        print "\t\t:::::: NAO PASSOU : $linha ::::: $d_mapa\n";
##        $karte = 0;
##      }      
    }
  }
  # fine parameters
      @la = split /\D+/, $d_latitude;
      @lo = split /\D+/, $d_longitude;
      $geocoord = "{{geocoordenadas|".$la[0]."_".$la[1]."_00_N_".$lo[0]."_".$lo[1]."_00_E|".$d_latitude." ".$d_longitude."}}";

      $comuna_sql = $comuna;
      $comuna_sql =~ s/ \(.*?\)//g;
      $d_interwiki = "[[it:$comuna]]";

  $sql = "\tINSERT INTO suica VALUES(NULL,\"$comuna_sql\",'$d_cantao','$d_site','$d_mapa',\"$d_distrito\",'$d_lingua',".
    "\"$d_latitude\",\"$d_longitude\",\"$geocoord\",'$d_altitude','$d_area','$d_densidade',\"$d_adjacentes\",\"$d_fraccoes\",".
    "'$d_pref_tel','$d_populacao','$d_codpostal','$d_bfs','$d_brasao',\"$d_interwiki\",\"$d_censo\",\"\")";
  $sql =~ s/[\'\"]\s* \s*[\'\"]/''/g;
  print $sql."\n";
  $statement = $db_handle->prepare($sql)
    or die "Couldn't prepare query '$sql': $DBI::errstr\n";

  $statement->execute()
    or die "Couldn't execute query '$sql': $DBI::errstr\n";
    
}

#while ($row_ref = $statement->fetchrow_hashref()) {
#    print "* $row_ref->{cur_title}\n";
#}

$db_handle->disconnect();

run_subst.pl[editar | editar código-fonte]

#!/usr/bin/perl
#
# Exemplo da lista: 
# cantao = "[[Appenzell Exterior]]", cantao_nome = "Appenzell Exterior"	cantao LIKE "Appenzello Esterno"
#

use DBI;

$dbuser = 'xxx';
$dbpwd = 'xxx';
$database = 'xxx';


$db_handle = DBI->connect("dbi:mysql:database=".$database.";host=localhost;user=".$dbuser.";password=".$dbpwd)
  or die "Couldn't connect to database: $DBI::errstr\n";

if (!open(FICH,"<substs.txt")) { die "$0: nao ha' cantoes? :)\n"; }
    
while (<FICH>) {
  ($fields, $where) = split /\t/;
  $cpt =~ s/\r\n//g;
  $sql = "UPDATE suica SET $fields WHERE $where";
  print $sql."\n";
  $statement = $db_handle->prepare($sql)  or die "Couldn't prepare query '$sql': $DBI::errstr\n";

  $statement->execute() or die "Couldn't execute query '$sql': $DBI::errstr\n";
}    

$db_handle->disconnect();

templatech.txt[editar | editar código-fonte]

{{SQLCONNECTION|***|**|***|**}}
{{SQLREFTABLE|suica|nome}}
{{SQLFIELD|suica|geocoord}}
{{Info/Comuna da Suíça|
|nome        = {{SQLFIELD|suica|nome}}
|bfs         = {{SQLFIELD|suica|bfs}}
|cantão      = {{SQLFIELD|suica|cantao}}
|distrito    = {{SQLFIELD|suica|distrito}}
|imagem      = <!-- Insira apenas o nome da imagem -->
|legenda     = <!-- Insira uma legenda para a imagem -->
|brasão      = {{SQLFIELD|suica|brasao}}
|área        = {{SQLFIELD|suica|area}}
|altitude    = {{SQLFIELD|suica|altitude}}
|população   = {{SQLFIELD|suica|populacao}}
|densidade   = {{SQLFIELD|suica|densidade}}
|censos      = {{SQLFIELD|suica|censo}}
|adjacentes  = {{SQLFIELD|suica|adjacentes}}
|fracções    = {{SQLFIELD|suica|fraccoes}}
|prefixo_tel = {{SQLFIELD|suica|pref_tel}}
|cód_postal  = {{SQLFIELD|suica|codpostal}}
|coordenadas = {{SQLFIELD|suica|latitude}} \
{{SQLFIELD|suica|longitude}}
|línguas     = {{SQLFIELD|suica|lingua}}
|mapa        = {{SQLFIELD|suica|mapa}}
|website     = {{SQLFIELD|suica|website}}
}}
'''{{SQLFIELD|suica|nome}}''' é uma [[comuna suíça|comuna]] da [[Suíça]], \
no [[Cantões da Suíça|Cantão]] {{SQLFIELD|suica|cantao}}, \
com cerca de {{SQLFIELD|suica|populacao}} habitantes. \
Estende-se por uma [[área]] de {{SQLFIELD|suica|area}} [[Quilómetro quadrado|km<sup>2</sup>]], \
de [[densidade populacional]] de {{SQLFIELD|suica|densidade}} hab/km<sup>2</sup>. \
Confina com as seguintes comunas: {{SQLFIELD|suica|adjacentes}}. 

A língua oficial nesta comuna é o {{SQLFIELD|suica|lingua}}.


<!--PLACEHOLDER: Não apague esta linha-->

{{esboço-geoch}}

[[Categoria:Comunas da Suíça]]
[[Categoria:Comunas do cantão {{SQLFIELD|suica|cantao_nome}}]]

{{SQLFIELD|suica|interwiki}}

disambigch.txt[editar | editar código-fonte]

{{SQLCONNECTION|xxxx|xxx|xxx|xxxx}}
{{SQLREFTABLE|frenchcom|nome}}
{{DISAMBIGSUFFIX|fixed|Franca}}
{{DISAMBIGSUFFIX|field|frenchcom|regiao_nome}}
{{DISAMBIGSUFFIX|field|frenchcom|departamento_nome}}
{{desambiguação}}

Por '''{{subst:PAGENAME}}''' pode estar à procura de:
* [[{{SQLFIELD|frenchcom|disambig}}|{{subst:PAGENAME}}]] - \
uma comuna na região de {{SQLFIELD|frenchcom|regiao_nome}}, \
departamento de {{SQLFIELD|frenchcom|departamento_nome}}, na França;


[[it:{{subst:PAGENAME}}]]