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
     } */
75
     } */
76
     }
76
     }
77
 
77
 
78
+    //TODO ELIMINAR PARA PROCESAR ZIPS, NO EL DIARIO
78
     private function downloadProcess($urlXML)
79
     private function downloadProcess($urlXML)
79
     {
80
     {
80
 
81
 
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
     private function downloadZip($urlXML)
120
     private function downloadZip($urlXML)
100
     {
121
     {
122
+        $fechaDescarga = $this->getFechaForDownloadZip();
101
         $fileName = basename($urlXML);
123
         $fileName = basename($urlXML);
102
-        $downladedZip = $this->downloadFile($fileName, $urlXML, $this->rutaDiariaFecha);
124
+        $downladedZip = $this->downloadFile($fileName, $urlXML . $fechaDescarga, $this->rutaDiariaFecha);
103
 
125
 
104
         if ($downladedZip) {
126
         if ($downladedZip) {
105
             $zip = new ZipArchive;
127
             $zip = new ZipArchive;
112
                 foreach ($archivosTotales as $file) {
134
                 foreach ($archivosTotales as $file) {
113
                     $this->getFile($this->rutaDiariaFecha . $file, $file);
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
     private function getFile($url, $fileName)
156
     private function getFile($url, $fileName)
148
         file_put_contents($this->rutaDiariaFecha . "/format/" . $fileName, $closureFormat);
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
     private function downloadFile($fileName, $url, $ruta)
186
     private function downloadFile($fileName, $url, $ruta)
172
     {
187
     {
173
         if (file_put_contents($ruta . $fileName, file_get_contents($url))) {
188
         if (file_put_contents($ruta . $fileName, file_get_contents($url))) {
195
 
210
 
196
     private function tablasCalculadas($idUltimaImportacion)
211
     private function tablasCalculadas($idUltimaImportacion)
197
     {
212
     {
198
-        $this->Parser_model->truncateTables("import_licitaciones_temp");
199
-
200
         $this->Parser_model->truncateTables("vista_datos_licitacion");
213
         $this->Parser_model->truncateTables("vista_datos_licitacion");
201
 
214
 
202
         $licitaciones = $this->Xlsexport_model->getLicitaciones($idUltimaImportacion);
215
         $licitaciones = $this->Xlsexport_model->getLicitaciones($idUltimaImportacion);

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

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

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

62
 
62
 
63
     public function getUrlArchivos()
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
         $result = $this->db->query($sql);
66
         $result = $this->db->query($sql);
67
         $datos['datos'] = $result->result();
67
         $datos['datos'] = $result->result();
68
         $datos['num_rows'] = $result->num_rows();
68
         $datos['num_rows'] = $result->num_rows();