Created
August 9, 2013 19:47
-
-
Save palamago/6196599 to your computer and use it in GitHub Desktop.
Agenda Cultural WS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('AppTask.php'); | |
class AgendaCulturalTask extends AppTask { | |
public function retrieveData($filter){ | |
try{ | |
$todayUrl = 'http://agendacultural.buenosaires.gob.ar/webservice/response/client.php?Method=GetListSearchToday&IdMixEventoLugar=&Tipo=&Titulo=&Resumen=&Hoy=TRUE&Manana=&EsteFinDeSemana=&ProximoFinDeSemana=&EnEsteMes=&DestacadoHome=&MarcaProximosEventos=&Imagen=&AlbumFlickr=&Facebook=&Youtube=&Twitter=&IdEventoPadre=&IdEventosRelacionados=&Hora=&Minutos=&IdTipoEvento=&DestacadoBoxPrimario=&Latitud=&Longitud=&OrdenarPor=&Orden=&Limit=&Offset='; | |
$data = file_get_contents($todayUrl); | |
$xml = simplexml_load_string($data); | |
$events = array(); | |
foreach ($xml->Item as $key => $item) { | |
$event = array(); | |
$event['id'] = (int) $item->IdMixEventoLugar; | |
$event['titulo'] = (string) $item->Titulo; | |
$event['titulo'] = str_replace("?", "'", $event['titulo']); | |
$event['resumen'] = (string) $item->Resumen; | |
$event['resumen'] = strip_tags($event['resumen']); | |
$event['inicio'] = (string) $item->FechaInicio; | |
$event['fin'] = (string) $item->FechaFin; | |
$event['lugar'] = (string) $item->Lugares; | |
$slug = $this->normaliza((string) $item->Titulo); | |
$slug = str_replace(' ', '-', $slug); | |
$event['imagen'] = 'http://fotos.agendacultural.buenosaires.gob.ar/'.$slug .'/'. (string) $item->Imagen; | |
$event['calificacion'] = (int) $item->Calificacion; | |
$events[] = $event; | |
} | |
//print_r($events); | |
return '{"hoy":'.json_encode($events).'}'; | |
} catch (Exception $e) { | |
$this->out('ERROR: ', $e->getMessage(), "\n"); | |
return false; | |
} | |
} | |
public function normaliza ($cadena){ | |
$originales = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ | |
ßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿŔŕ'; | |
$modificadas = 'aaaaaaaceeeeiiiidnoooooouuuuy | |
bsaaaaaaaceeeeiiiidnoooooouuuyybyRr'; | |
$cadena = utf8_decode($cadena); | |
$cadena = strtr($cadena, utf8_decode($originales), $modificadas); | |
$cadena = strtolower($cadena); | |
return utf8_encode($cadena); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment