El Clima / The weather

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

El Clima / The weather

Post by andyglezl »

Hola a todos
Estoy intentando obtener los datos del CLIMA del día.
Encontre esta página donde tecleando lo siguiente: http://wttr.in/Guadalajara+Jalisco
(puedes tratar con tu ciudad+estado) en el navegador, me despliega la informacion de la imagen siguiente.

La intención es obtener estos datos y mostrarlos en una ventana con HMG.
Alguna idea ??
*----------------------------------------------------------------------------------------------------------------------
Hi all
I'm trying to get the WEATHER data for the day.
I found this page where typing the following: http://wttr.in/Guadalajara+Jalisco
(you can try with your city + state) in the browser, it displays the information of the following image.

The intention is to obtain this data and display it in a window with HMG.
Any ideas ??
Clima.png
Clima.png (52.16 KiB) Viewed 2413 times
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: El Clima / The weather

Post by serge_girard »

Andrés,

See little demo. It will return the HTML code, then you will extract yourself what you need.

Code: Select all

HBC
inc=yes
head=native
libs=hbssl
libs=libeay32
libs=ssleay32


HBP
DEMO.PRG
hbssl.hbc


PRG
#include "hmg.ch"
#INCLUDE "Fileio.CH"
#require "hbtip"
#require "hbssl"
REQUEST __HBEXTERN__HBSSL__



FUNCTION MAIN()
/***********************/
LOCAL cURL, cHtml, vRet, cX1

XHTTP := 'http://wttr.in/Guadalajara+Jalisco' 
cX1	:= STRTRAN(XHTTP,'www.','')
 
cHtml	:= Read_URL( cX1 )

IF!EMPTY(cHtml)
	vRet	:= Extract_IP(cHtml)  
   msginfo(vRet) 
	RETURN IIF(EMPTY(vRET), 'Site unreachable!', vRet)
ELSE
	RETURN  ''
ENDIF





FUNCTION Extract_IP(cHtml)
/***********************/
LOCAL Pos, PosF
Pos := AT('<BODY', UPPER(cHtml) )
// msginfo(cHtml ,'2') 
IF Pos < 1
	RETURN 0
ENDIF
cHtml := SUBSTR( cHtml, Pos+5 )
 
RETURN ALLTRIM(cHtml)






FUNCTION Read_URL( cUrl )
/***************************/
LOCAL oUrl, oCli, cRes := ''

BEGIN SEQUENCE
	oUrl = TUrl():New( cUrl )
	IF EMPTY( oUrl )
		BREAK
	ENDIF
	oCli = TIpClientHttp():New( oUrl )
	IF EMPTY( oCli )
		BREAK
	ENDIF
	oCli:nConnTimeout = 20000
	IF !oCli:Open( oUrl )
		BREAK
	ENDIF
	cRes := oCli:Read()
	oCli:Close()
END SEQUENCE
RETURN cRes
That is how I extract my weather information!

Serge
There's nothing you can do that can't be done...
User avatar
vagblad
Posts: 160
Joined: Tue Jun 18, 2013 12:18 pm
DBs Used: MySQL,DBF
Location: Thessaloniki, Greece

Re: El Clima / The weather

Post by vagblad »

Serge was faster!

But since i prepared a little demo i'll post it as well :)

PS. Mind you its in MiniGUI but you can see how it works.
Attachments
Weather.zip
(808.05 KiB) Downloaded 199 times
Vagelis Prodromidis
Email: vagblad@gmail.com, Skype: vagblad
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: El Clima / The weather

Post by andyglezl »

Hola Serge y Vagblad

Muchas Gracias por contestar !
Voy a probarlos

*------------------------------------------------------------------------------------------------------------
Hello Serge and Vagblad

Thank you very much for answering !
I'm going to try them
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: El Clima / The weather

Post by andyglezl »

Gracias de nuevo Serge

Ya hice una prueba y me despliega el HTML.

Adicionalmente, puse algunos parametros al link del clima
y suprime muchos "tags" facilitando el trabajo.
*-----------------------------------------------------------------------------------------
Thanks again Serge

I already did a test and it displays the HTML.

Additionally, I put some parameters to the weather link
and it suppresses many "tags" facilitating the work.


'http://wttr.in/Guadalajara+Jalisco?ptT&lang=es '

Clima3.png
Clima3.png (172.38 KiB) Viewed 2315 times
Clima4.png
Clima4.png (2.09 KiB) Viewed 2302 times
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: El Clima / The weather

Post by andyglezl »

Hola a Todos, aquí les dejo un ejemplo actualizado por si a alguien le es util.
*--------------------------------------------------------------------------------------------
Hi Everyone, here is an updated example in case someone is useful.

Clima.png
Clima.png (5.52 KiB) Viewed 2076 times
TheWeather.zip
(1.08 KiB) Downloaded 181 times
Andrés González López
Desde Guadalajara, Jalisco. México.
Post Reply