FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
Herramientas | Buscar en Tema | Desplegado |
#1
|
||||
|
||||
Obtener temperatura a través de internet
Quiza os habeis preguntado alguna vez como hacen esos programas que se colocan en la barra de tareas y dan informacion sobre el tiempo (temperatura, humedad, etc). Pues lo que hacen es consultar una base de datos a traves de internet con informacion proporcionada por difenetes centros como, por ejemplo, los aeropuertos. Esta es la forma en la que, por ejemplo, aptua el gweather de gnome, que consulta al "National Weather Service" http://www.weather.gov/
Pues bien, podemos hacer una pequeña funcion que nos devuelva la temperatura, a partir del codigo del aeropueto. Algo asi:
Por ejemplo para obtener la temperatura de La Coruna (Alvedro), tenemos que usar el codigo LECO. Algo asi:
Para obtener el código del aeropuerto mas cercano a nuestra ciudad, puedes usar esta pagina: http://weather.noaa.gov/weather/ES_cc.html En esta pagina puedes escoger el aeropuerto, y en la pagina de cada aeropuerto tienes el código entre paréntesis, junto a las coordenadas. Este es solo un pequeño ejemplo de lo que se puede conseguir. Analizando mejor el texto podemos obtener, además de la temperatura, la humedad, el viento, la presión, etc ... pero como delphi no cuenta con esa maravilla de las "expresiones regulares", el analizar la cadena se me hacia un poco tedioso. Pero si alguien se anima que lo ponga por aquí. El formato en el que esta codificado es el siguiente: http://weather.cod.edu/notes/metar.html Edito: Aquí dejo una versión recortada de la función Temperatura:
|
#2
|
||||
|
||||
Esta muy bueno, yo lo probe para el caso de Buenos Aires, Argentina, y funciona muy bien, todavia no lo logre hacer andar con los demas datos, es bastante feo tener que recorrer todo el string.
Saludos |
#3
|
|||
|
|||
yo lo hice de manera mas sencilla bajando el xml con indy http por ejemplo bajar este xml http://weather.yahooapis.com/forecastrss?p=ARMS0120&u=C.xml
es de puerto iguazu argentina, una vez que lo tenemos lo tratas igual que a un txt y con readln, lo voy leyendo linea por linea, despues busco con pos() la cadena, temp, humidity, etc y listo, es muy sencillo y menos complicado creo yo...bueno un saludo a todos...FEDE |
|
|
|