mirror of
https://github.com/inigoflores/ds-codigos-postales-ine-es.git
synced 2024-06-16 10:04:10 +02:00
Add nucleo_nombre urbano to entidades. Fix titleCase()
This commit is contained in:
parent
491db96ada
commit
55bfee5a08
15
scripts/README.md
Normal file → Executable file
15
scripts/README.md
Normal file → Executable file
|
@ -9,12 +9,13 @@ Si no los encuentra, los descarga.
|
||||||
|
|
||||||
$ php script.php [COMMAND SUBCOMMAND]] [OPTIONS]
|
$ php script.php [COMMAND SUBCOMMAND]] [OPTIONS]
|
||||||
|
|
||||||
Si se invoca sin subcomandos o argumentos, executa:
|
Si se invoca sin subcomandos o argumentos, ejecuta:
|
||||||
|
|
||||||
1. download all
|
1. download all
|
||||||
2. process all
|
2. process all
|
||||||
3. update
|
3. merge
|
||||||
4. convert-to-json
|
4. update
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Opciones
|
### Opciones
|
||||||
|
@ -28,7 +29,6 @@ Si se invoca sin subcomandos o argumentos, executa:
|
||||||
year YEAR MONTH Descarga únicamente el periodo YEAR MONTH (Month es 1 ó 7)
|
year YEAR MONTH Descarga únicamente el periodo YEAR MONTH (Month es 1 ó 7)
|
||||||
all Descarga todos los años
|
all Descarga todos los años
|
||||||
|
|
||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
|
|
||||||
--force, -f Fuerza la descarga de los archivos fuente, aunque existan
|
--force, -f Fuerza la descarga de los archivos fuente, aunque existan
|
||||||
|
@ -45,11 +45,18 @@ Si se invoca sin subcomandos o argumentos, executa:
|
||||||
all Procesa todo
|
all Procesa todo
|
||||||
|
|
||||||
|
|
||||||
|
merge Hace el merge con ds-organizacion-administrativa para obtener el
|
||||||
|
nombre del municipio, que no viene en los archivos fuente.
|
||||||
|
|
||||||
|
|
||||||
convert-to-json Convierte todos los archivos .csv almacenados en /data a .json.
|
convert-to-json Convierte todos los archivos .csv almacenados en /data a .json.
|
||||||
|
|
||||||
|
|
||||||
update Actualiza el archivo datapackage.json
|
update Actualiza el archivo datapackage.json
|
||||||
|
|
||||||
|
OPTIONS
|
||||||
|
|
||||||
|
--json, -j Habilita la creación de recursos para los archivos JSON en datapackage.json
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -84,17 +84,27 @@ class Config
|
||||||
"description" => "Código INE del municipio",
|
"description" => "Código INE del municipio",
|
||||||
"pattern" => "[0-9]{5}"
|
"pattern" => "[0-9]{5}"
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
"name" => "municipio_nombre",
|
||||||
|
"type" => "string",
|
||||||
|
"description" => "Nombre del municipio",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"name" => "codigo_unidad_poblacional",
|
||||||
|
"type" => "number",
|
||||||
|
"description" => "Codigo unidad poblacional",
|
||||||
|
"pattern" => "[0-9]{7}"
|
||||||
|
],
|
||||||
[
|
[
|
||||||
"name" => "entidad_singular_nombre",
|
"name" => "entidad_singular_nombre",
|
||||||
"type" => "string",
|
"type" => "string",
|
||||||
"description" => "Nombre entidad singular",
|
"description" => "Nombre entidad singular",
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"name" => "municipio_nombre",
|
"name" => "nucleo_nombre",
|
||||||
"type" => "string",
|
"type" => "string",
|
||||||
"description" => "Nombre del municipio",
|
"description" => "Nombre nucleo/diseminado",
|
||||||
],
|
],
|
||||||
|
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
@ -139,11 +149,22 @@ class Config
|
||||||
"description" => "Código INE del municipio",
|
"description" => "Código INE del municipio",
|
||||||
"pattern" => "[0-9]{5}"
|
"pattern" => "[0-9]{5}"
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
"name" => "codigo_unidad_poblacional",
|
||||||
|
"type" => "number",
|
||||||
|
"description" => "Codigo unidad poblacional",
|
||||||
|
"pattern" => "[0-9]{7}"
|
||||||
|
],
|
||||||
[
|
[
|
||||||
"name" => "entidad_singular_nombre",
|
"name" => "entidad_singular_nombre",
|
||||||
"type" => "string",
|
"type" => "string",
|
||||||
"description" => "Nombre entidad singular",
|
"description" => "Nombre entidad singular",
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
"name" => "nucleo_nombre",
|
||||||
|
"type" => "string",
|
||||||
|
"description" => "Nombre nucleo/diseminado",
|
||||||
|
],
|
||||||
|
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
@ -199,11 +220,22 @@ class Config
|
||||||
"description" => "Código INE del municipio",
|
"description" => "Código INE del municipio",
|
||||||
"pattern" => "[0-9]{5}"
|
"pattern" => "[0-9]{5}"
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
"name" => "codigo_unidad_poblacional",
|
||||||
|
"type" => "number",
|
||||||
|
"description" => "Codigo unidad poblacional",
|
||||||
|
"pattern" => "[0-9]{7}"
|
||||||
|
],
|
||||||
[
|
[
|
||||||
"name" => "entidad_singular_nombre",
|
"name" => "entidad_singular_nombre",
|
||||||
"type" => "string",
|
"type" => "string",
|
||||||
"description" => "Nombre entidad singular",
|
"description" => "Nombre entidad singular",
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
"name" => "nucleo_nombre",
|
||||||
|
"type" => "string",
|
||||||
|
"description" => "Nombre nucleo/diseminado",
|
||||||
|
],
|
||||||
[
|
[
|
||||||
"name" => "year",
|
"name" => "year",
|
||||||
"type" => "number",
|
"type" => "number",
|
||||||
|
|
|
@ -13,7 +13,7 @@ class MergeCommand extends ConsoleKit\Command
|
||||||
|
|
||||||
public function execute(array $args, array $options = array())
|
public function execute(array $args, array $options = array())
|
||||||
{
|
{
|
||||||
$box = new ConsoleKit\Widgets\Box($this->getConsole(), 'Haciendo merge con ds-organizacion-administrativagit');
|
$box = new ConsoleKit\Widgets\Box($this->getConsole(), 'Haciendo merge con ds-organizacion-administrativa');
|
||||||
$box->write();$this->getConsole()->writeln("");
|
$box->write();$this->getConsole()->writeln("");
|
||||||
|
|
||||||
shell_exec('
|
shell_exec('
|
||||||
|
@ -29,10 +29,10 @@ class MergeCommand extends ConsoleKit\Command
|
||||||
");
|
");
|
||||||
|
|
||||||
shell_exec('
|
shell_exec('
|
||||||
curl https://raw.githubusercontent.com/codeforspain/ds-organizacion-administrativa/master/data/municipios.csv \
|
curl https://raw.githubusercontent.com/codeforspain/ds-organizacion-administrativa/master/data/municipios.csv \
|
||||||
| csvcut -c \'municipio_id,nombre\' \
|
| csvcut -c "municipio_id,nombre" \
|
||||||
| csvjoin --snifflimit 0 -I -c "municipio_id" ../data/codigos_postales_municipiosid_entidades.csv - \
|
| csvjoin --snifflimit 0 -I -c "municipio_id" ../data/codigos_postales_municipiosid_entidades.csv - \
|
||||||
| csvcut -c "codigo_postal,entidad_singular_nombre,municipio_id,nombre" \
|
| csvcut -c "codigo_postal,municipio_id,nombre,codigo_unidad_poblacional,entidad_singular_nombre,nucleo_nombre" \
|
||||||
> ../data/codigos_postales_municipios_entidades.csv
|
> ../data/codigos_postales_municipios_entidades.csv
|
||||||
');
|
');
|
||||||
|
|
||||||
|
|
|
@ -167,18 +167,27 @@ class ProcessCommand extends ConsoleKit\Command
|
||||||
}
|
}
|
||||||
|
|
||||||
while (($line = fgets($zippedSource)) !== false) {
|
while (($line = fgets($zippedSource)) !== false) {
|
||||||
|
$line = iconv("windows-1252", "UTF-8", $line);
|
||||||
|
|
||||||
$codigo_postal = substr($line,42,5);
|
$codigo_postal = substr($line,42,5);
|
||||||
$municipio_id = substr($line,0,5);
|
$municipio_id = substr($line,0,5);
|
||||||
$nombre_entidad_singular = $this->titleCase(
|
|
||||||
(iconv("windows-1252", "UTF-8", trim(substr($line,110,25))))
|
$codigo_unidad_poblacional = substr($line,13,7);
|
||||||
);
|
//$nombre_entidad_colectiva = $this->titleCase(trim(substr($line,85,25)));
|
||||||
|
$nombre_entidad_singular = $this->titleCase(trim(substr($line,110,25)));
|
||||||
|
$nombre_nucleo = $this->titleCase(trim(substr($line,135,25)));
|
||||||
|
|
||||||
if ($includeYear) {
|
if ($includeYear) {
|
||||||
$items[$codigo_postal.$municipio_id.$year.$month] = compact('codigo_postal','municipio_id', 'year', 'month');
|
$items[$codigo_postal.$municipio_id.$year.$month] =
|
||||||
$itemsEntidades[$codigo_postal.$municipio_id.$nombre_entidad_singular.$year.$month] = compact('codigo_postal','municipio_id','nombre_entidad_singular','year','month');
|
compact('codigo_postal','municipio_id', 'year', 'month');
|
||||||
|
$itemsEntidades[$codigo_postal.$municipio_id.$codigo_unidad_poblacional.$year.$month] =
|
||||||
|
compact('codigo_postal','municipio_id','codigo_unidad_poblacional',
|
||||||
|
'nombre_entidad_singular','nombre_nucleo','year','month');
|
||||||
} else {
|
} else {
|
||||||
$items[$codigo_postal.$municipio_id] = compact('codigo_postal','municipio_id');
|
$items[$codigo_postal.$municipio_id] = compact('codigo_postal','municipio_id');
|
||||||
$itemsEntidades[$codigo_postal.$municipio_id.$nombre_entidad_singular] = compact('codigo_postal','municipio_id','nombre_entidad_singular');
|
$itemsEntidades[$codigo_postal.$municipio_id.$codigo_unidad_poblacional] =
|
||||||
|
compact('codigo_postal','municipio_id','codigo_unidad_poblacional',
|
||||||
|
'nombre_entidad_singular','nombre_nucleo');
|
||||||
}
|
}
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
|
@ -197,7 +206,21 @@ class ProcessCommand extends ConsoleKit\Command
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function titleCase($string, $delimiters = array(" ", "-", "/"), $exceptions = array("de", "del", "la")) {
|
/**
|
||||||
|
* @param $string Cadena de texto a convertir
|
||||||
|
* @param array $delimiters Carácteres delimitadores
|
||||||
|
* @param array $exceptions Palabras a las que no se les cambia la capitalización
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function titleCase($string, $delimiters = array(), $exceptions = array()) {
|
||||||
|
|
||||||
|
if (empty($delimiters)) {
|
||||||
|
$delimiters = array(" ", "-", "/",",","'");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($exceptions)) {
|
||||||
|
$exceptions = array("de", "del", "la","II",'III','IV','XIII','XXIII');
|
||||||
|
}
|
||||||
|
|
||||||
$string = mb_convert_case($string, MB_CASE_TITLE, "UTF-8");
|
$string = mb_convert_case($string, MB_CASE_TITLE, "UTF-8");
|
||||||
|
|
||||||
|
@ -207,9 +230,11 @@ class ProcessCommand extends ConsoleKit\Command
|
||||||
foreach ($words as $wordnr => $word){
|
foreach ($words as $wordnr => $word){
|
||||||
|
|
||||||
$wordLowerCase = strtolower($word);
|
$wordLowerCase = strtolower($word);
|
||||||
if (in_array($wordLowerCase, $exceptions)){
|
$wordUpperCase = strtoupper($word);
|
||||||
// check exceptions list for any words that should be in lower case
|
if (in_array($wordLowerCase, $exceptions)){ // check exceptions list for any words that should be in lower case
|
||||||
$word = $wordLowerCase;
|
$word = $wordLowerCase;
|
||||||
|
} else if (in_array($wordUpperCase, $exceptions)){ // check exceptions list for any words that should be in upper case
|
||||||
|
$word = $wordUpperCase;
|
||||||
}
|
}
|
||||||
elseif (!in_array($word, $exceptions) ){
|
elseif (!in_array($word, $exceptions) ){
|
||||||
// convert to uppercase (non-utf8 only)
|
// convert to uppercase (non-utf8 only)
|
||||||
|
|
2
scripts/lib/UpdateCommand.php
Normal file → Executable file
2
scripts/lib/UpdateCommand.php
Normal file → Executable file
|
@ -21,7 +21,7 @@ class UpdateCommand extends ConsoleKit\Command
|
||||||
$box->write();$this->getConsole()->writeln("");
|
$box->write();$this->getConsole()->writeln("");
|
||||||
|
|
||||||
// Comprobamos si hay que omitir JSON
|
// Comprobamos si hay que omitir JSON
|
||||||
if (!isset($options['nojson']) && !isset($options['n'])){
|
if (isset($options['json']) || isset($options['j'])){
|
||||||
foreach ( Config::$datapackage['resources'] as $resource){
|
foreach ( Config::$datapackage['resources'] as $resource){
|
||||||
$resource['format'] = 'json';
|
$resource['format'] = 'json';
|
||||||
$parts = explode('.',$resource['path']);
|
$parts = explode('.',$resource['path']);
|
||||||
|
|
|
@ -21,7 +21,7 @@ if (sizeof($argv)==1) {
|
||||||
$console->run(['process']);
|
$console->run(['process']);
|
||||||
//$console->run(['convert-to-json']); // No generamos los archivos json, alguno sobrepasa los 100 Mb (limite Github)
|
//$console->run(['convert-to-json']); // No generamos los archivos json, alguno sobrepasa los 100 Mb (limite Github)
|
||||||
$console->run(['merge']);
|
$console->run(['merge']);
|
||||||
$console->run(['update','--nojson']);
|
$console->run(['update']);
|
||||||
} else {
|
} else {
|
||||||
$console->run();
|
$console->run();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user