-
Notifications
You must be signed in to change notification settings - Fork 0
/
docstosql.sh
executable file
·52 lines (38 loc) · 1.17 KB
/
docstosql.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/php
<?php
error_reporting(-1);
ini_set('display_errors', 1);
$file = $argv[1];
$target = $argv[2];
if (!$file) {
echo "debe especificar un zip de origen\n";exit();
}
if (!file_exists($file)) {
echo "el archivo especificado zip de origen no existe\n";exit();
}
if (!$target) {
echo "debe especificar un archivo sql de destino\n";exit();
}
if (file_exists($target)) {
echo "el archivo especificado sql de destino ya existe\n";exit();
}
$file = dirname(__FILE__) . "/" . $file;
$target = dirname(__FILE__) . '/' . $target;
$tmp = dirname(__FILE__) . '/tmp';
$cwd = getcwd();
if (file_exists($tmp)) {
echo "el directorio tmp debe estar vacio\n";exit();
}
echo "creando directorio temporal\n";
`mkdir $tmp`;
chdir('tmp');
echo "descomprimiendo\n";
`unzip $file`;
echo "creando csvs\n";
`libreoffice --headless --convert-to csv * --outdir .`;
echo "parseando csv\n";
`find . -type f -name "*.csv" | xargs cat | egrep -v "^[,]+$" | egrep -v "^,Fecha" | egrep -v "^,Ultimos Movimientos" | egrep -v "^,Cuenta,Cuenta Unica 270-364477" > resultado.txt`;
echo "generando sql\n";
`../convertir.php resultado.txt > $target`;
echo "eliminando directorio temporal\n";
`rm -Rf $tmp`;