Browse Source

Parametrizar la fecha de los zips de los urls. Solamente descargarse zips que esten activas

Nermosis 3 years ago
parent
commit
425f07eddf

+ 37 - 24
application/controllers/Parser.php View File

@@ -75,6 +75,7 @@ class Parser extends CI_Controller
75 75
     } */
76 76
     }
77 77
 
78
+    //TODO ELIMINAR PARA PROCESAR ZIPS, NO EL DIARIO
78 79
     private function downloadProcess($urlXML)
79 80
     {
80 81
 
@@ -96,10 +97,31 @@ class Parser extends CI_Controller
96 97
         }
97 98
     }
98 99
 
100
+    private function readNextAttribute($archivo)
101
+    {
102
+        $enlace = "";
103
+        foreach ($archivo['link'] as $row) {
104
+            $attrNext = $row['@attributes']['rel'];
105
+            $attrHref = $row['@attributes']['href'];
106
+
107
+            if ($attrNext === "next") {
108
+                if (!strpos($attrHref, "licitacionesPerfilesContratanteCompleto3_2021")) { //"20220127_")) {
109
+                    $enlace = $attrHref;
110
+                } else {
111
+                    $enlace = "";
112
+                }
113
+                //$enlace = $attrHref;
114
+            }
115
+        }
116
+
117
+        return $enlace;
118
+    }
119
+
99 120
     private function downloadZip($urlXML)
100 121
     {
122
+        $fechaDescarga = $this->getFechaForDownloadZip();
101 123
         $fileName = basename($urlXML);
102
-        $downladedZip = $this->downloadFile($fileName, $urlXML, $this->rutaDiariaFecha);
124
+        $downladedZip = $this->downloadFile($fileName, $urlXML . $fechaDescarga, $this->rutaDiariaFecha);
103 125
 
104 126
         if ($downladedZip) {
105 127
             $zip = new ZipArchive;
@@ -112,10 +134,23 @@ class Parser extends CI_Controller
112 134
                 foreach ($archivosTotales as $file) {
113 135
                     $this->getFile($this->rutaDiariaFecha . $file, $file);
114 136
                 }
115
-
116 137
             }
138
+        }
139
+    }
140
+
141
+    private function getFechaForDownloadZip(): String
142
+    {
143
+        $result = "_";
144
+        $anyo = date("Y");
145
+        $mes = date("m", strtotime("-1 months"));
146
+        $dia = date("d");
117 147
 
148
+        if ($dia == "01") {
149
+            $result .= $anyo . $mes . ".zip";
150
+        } else {
151
+            $result .= $anyo . $mes . ".zip";
118 152
         }
153
+        return $result;
119 154
     }
120 155
 
121 156
     private function getFile($url, $fileName)
@@ -148,26 +183,6 @@ class Parser extends CI_Controller
148 183
         file_put_contents($this->rutaDiariaFecha . "/format/" . $fileName, $closureFormat);
149 184
     }
150 185
 
151
-    private function readNextAttribute($archivo)
152
-    {
153
-        $enlace = "";
154
-        foreach ($archivo['link'] as $row) {
155
-            $attrNext = $row['@attributes']['rel'];
156
-            $attrHref = $row['@attributes']['href'];
157
-
158
-            if ($attrNext === "next") {
159
-                if (!strpos($attrHref, "licitacionesPerfilesContratanteCompleto3_2021")) { //"20220127_")) {
160
-                    $enlace = $attrHref;
161
-                } else {
162
-                    $enlace = "";
163
-                }
164
-                //$enlace = $attrHref;
165
-            }
166
-        }
167
-
168
-        return $enlace;
169
-    }
170
-
171 186
     private function downloadFile($fileName, $url, $ruta)
172 187
     {
173 188
         if (file_put_contents($ruta . $fileName, file_get_contents($url))) {
@@ -195,8 +210,6 @@ class Parser extends CI_Controller
195 210
 
196 211
     private function tablasCalculadas($idUltimaImportacion)
197 212
     {
198
-        $this->Parser_model->truncateTables("import_licitaciones_temp");
199
-
200 213
         $this->Parser_model->truncateTables("vista_datos_licitacion");
201 214
 
202 215
         $licitaciones = $this->Xlsexport_model->getLicitaciones($idUltimaImportacion);

+ 0 - 7
application/libraries/ParserFile.php View File

@@ -40,17 +40,13 @@ class ParserFile
40 40
         $files = get_filenames($this->rutaDiaria, true);
41 41
         $filename = "";
42 42
         $xml = "";
43
-        $json = "";
44 43
         $array = "";
45 44
         $aux = 0;
46 45
         $resultEntries = array();
47
-        $contador = 0;
48
-
49 46
         $stats = array();
50 47
 
51 48
         foreach ($files as $file) {
52 49
             $filename = basename($file);
53
-            $contador++;
54 50
             $entrada = file_get_contents($file);
55 51
             $xml = simplexml_load_string($entrada, "SimpleXMLElement", LIBXML_NOCDATA);
56 52
             $array = json_decode(json_encode($xml), true);
@@ -62,9 +58,6 @@ class ParserFile
62 58
                 $this->CI->Parser_model->truncateTables($row->tabla_sucia);
63 59
             }
64 60
 
65
-            gc_mem_caches();
66
-            gc_collect_cycles();
67
-
68 61
             foreach ($array['entry'] as $clave => $row) {
69 62
 
70 63
                 $existLicitacionActualizada = $this->getDatosLicitacion($row);

+ 1 - 1
application/models/Parser_model.php View File

@@ -62,7 +62,7 @@ class Parser_model extends CI_Model
62 62
 
63 63
     public function getUrlArchivos()
64 64
     {
65
-        $sql = "SELECT * FROM config_tipo_licitacion_tablas";
65
+        $sql = "SELECT * FROM config_tipo_licitacion_tablas WHERE activo = 1";
66 66
         $result = $this->db->query($sql);
67 67
         $datos['datos'] = $result->result();
68 68
         $datos['num_rows'] = $result->num_rows();