Пример #1
0
 foreach ($genreList as $genreData) {
     $genre = $genreData->idgrupo;
     $log->add("fetching track info for genre {$genre} (" . $genreData->nombre . ")");
     $finished = FALSE;
     $fetched = 0;
     while (!$finished) {
         $count = FALSE;
         $intentos = 0;
         while ($count == FALSE && $intentos < 3) {
             $intentos++;
             $url = "http://maxx.me.net-m.net/me/maxx/{$contractId}/items?start={$start}&contentTypeKey=FULLTRACK&maxSize={$size}&contentGroupId={$genre}";
             $log->add("reading {$url} (try #{$intentos})");
             $xmlContents = file_get_contents($url);
             $doc = new DOMDocument();
             $doc->loadXML($xmlContents);
             $count = getTrackCountResult($doc);
             if ($count != FALSE) {
                 $log->add("got {$count} results");
             } else {
                 $log->add("error reading results");
                 avisoCel("could not read xml (tracks)");
                 // pausa de 3 secs (posible server restart o error en netm, esperamos)
                 sleep(3);
             }
         }
         if ($count === FALSE) {
             // si no se pudo leer resultados, y se superaron los reintentos, termino el proceso
             $finished = TRUE;
             $log->add("too many retries with error");
             // enviar aviso cel
             $log->add("sending sms notification");
Пример #2
0
 public function fetchXML($icpn, $oLog = NULL)
 {
     $log = $oLog;
     $finished = FALSE;
     $fetched = 0;
     $contractId = $this->contractId;
     while (!$finished) {
         $count = FALSE;
         $intentos = 0;
         while ($count == FALSE && $intentos < 3) {
             $intentos++;
             $url = "http://maxx.me.net-m.net/me/maxx/{$contractId}/items?contentTypeKey=FT_BUNDLE&icpn={$icpn}";
             $log->add("reading {$url} (try #{$intentos})");
             $xmlContents = file_get_contents($url);
             $doc = new DOMDocument();
             $doc->loadXML($xmlContents);
             $count = getTrackCountResult($doc);
             if ($count != FALSE) {
                 $log->add("got {$count} results");
             } else {
                 $log->add("error reading results");
                 avisoCel("could not read xml (albums)");
                 // pausa de 3 secs (posible server restart o error en netm, esperamos)
                 sleep(3);
             }
         }
         if ($count === FALSE) {
             // si no se pudo leer resultados, y se superaron los reintentos, termino el proceso
             $finished = TRUE;
             $log->add("too many retries with error");
             // enviar aviso cel
             $log->add("sending sms notification");
             avisoCel("could not read xml (artists-albums)");
             $newXML = FALSE;
         } else {
             // se obtuvo un nuevo resultado
             if ($count > 0) {
                 $fetched++;
             }
             $newXML = TRUE;
         }
         // si no hay resultado de busqueda, termino el proceso
         if ($count == 0) {
             $finished = TRUE;
         }
         if ($newXML == TRUE) {
             // si se obtuvieron resultados y no se termino, guardo el xml y sigo buscando mas
             $xmlName = date("Ymd") . "-albums_" . $fetched . "-" . date("His") . ".xml";
             $fName = TMP_DIR . "/" . $xmlName;
             $log->add("saving xml content to {$fName}");
             $doc->save($fName);
         }
         $log->save(TRUE);
         if ($newXML == TRUE) {
             $result = $doc->getElementsByTagName("item");
             // cada item corresponde a un album (o bundle en lenguaje netm)
             if ($result->length > 0) {
                 $ok = 0;
                 $error = 0;
                 // si tengo albums para recorrer
                 foreach ($result as $itemNumber => $xmlTrack) {
                     $xmlItem = $result->item($itemNumber);
                     if ($xmlItem->hasAttributes()) {
                         $this->setFromXML($xmlItem);
                         $ok++;
                     } else {
                         // no se pudo leer los datos del track
                         $log->add("ERROR: no se pudieron obtener datos del track en: {$xmlName}");
                         $err++;
                     }
                 }
                 $log->add("finished processing {$xmlName}... total={$count}, Ok={$ok}, error={$error}");
                 $finished = TRUE;
                 // todo ok, salimos ;)
             } else {
                 // no hay items para procesar
                 $log->add("ERROR: no se encontraron items para procesar en: {$xmlName}");
             }
         } else {
             // no hay mas resultados y se termino el proceso, no hay que guardar nada
             $log->add("finished getting tracks for icpn {$icpn} (" . $icpnData->prd_title . ")");
         }
     }
     //	$log->add("album fetched $fetched xml");
     //	$log->save(TRUE);
 }