FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour un pequeño ejemplo ...meteo.prg
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
un pequeño ejemplo ...meteo.prg
Posted: Mon Dec 08, 2014 05:59 PM
Segui un poco con el ejemplo del uso de servicio meteorológico y lo he completado un poco mas .
Aqui dejo el código del ejemplo, funciona bien si no usas proxi , lo colocas como meteo.prg en samples y lo compilas .
Code (fw): Select all Collapse
// Our first DialogBox sample

#include "FiveWin.ch"
#include "ttitle.ch"

function Main()
  local obmp ,cBmp 
  local oDlg, oIco ,cCity:= "Marbella"+space(20)
  local cUrl := "http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"
  local ofont
   
   DEFINE Font ofont NAME "Verdana" SIZE 0,14 
    
   DEFINE ICON oIco FILE "..\icons\fivewin.ico"

   DEFINE DIALOG oDlg TITLE "Ciudad a buscar" ;
      ICON oIco SIZE 350, 240

   @ 30,10  IMAGE oBmp FILE cBmp OF oDlg size 142,35 pixel NOBORDER 
     
     obmp:lTransparent := .t.
     cargaBmp(cUrl,oBmp)
     
   //  oBmp:display()
       
   
     @ 60, 10 SAY "Introduce la ciudad a buscar :" size 100, 12 ;
                        FONT oFont pixel OF oDlg
     
     @ 70, 10 GET cCity size 120, 12 FONT oFont pixel OF oDlg 

     @ 105, 85 BUTTON "&Buscar" SIZE 40, 12 OF oDlg pixel ;
              FONT oFont ; 
              ACTION llamada(cCity)

     @ 105,130 BUTTON "&Salir" SIZE 40, 12 pixel OF oDlg;
               FONT oFont ; 
               ACTION oDlg:End()

   ACTIVATE DIALOG oDlg CENTERED ;
    ON INIT  DlgBarTitle( oDlg, "  Servicio Metereologico","c:\fwh\bitmaps\alphaBmp\weather.bmp" ,44 )  ;
    ON PAINT DlgStatusBar(oDlg, 68,, .t. ) 
   
return nil

//------------------------------------------------------------------------------

Function cargaBmp(cUrl,oImage)
local cResp := loadBmp(cUrl)
local nZeroZeroClr
 if !Empty( cResp ) 
     // oImage:LoadFromString( cResp )
    oImage:LoadFromMemory( cResp )
    oImage:HasAlpha()
    oImage:Refresh()
 endif
Return nil

//------------------------------------------------------------------------------

//------------------------------------------------------------------------------

Function loadBmp(cUrl)
local oHttp
local cResp := nil

   Try
      oHttp := CreateObject( "winhttp.winhttprequest.5.1" )
      oHttp:Open("GET", cUrl, .f. )
      oHttp:Send()
      cResp := oHttp:ResponseBody()
          
   Catch
      MsgStop( "Error" )
      Return cResp
   End Try
  
Return cResp

//------------------------------------------------------------------------------




Function llamada(cCity)
local oHttp
local cResp
local cDir
local Formato :=  "json"  // "xml"   
local cUnits:= "c"

cDir := "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1)"
cDir:= cDir + " where text= '"+ cCity +"' ) and u='"+cUnits+"'&format=" + Formato
 
 Try
      oHttp := CreateObject("winhttp.winhttprequest.5.1")
      oHttp:Open("GET", cDir, .f. )
      oHttp:Send()
      cResp := oHttp:ResponseText()
     // memowrit("eltiempo.txt",cResp )
     // msginfo("grabado")
     // winexec( "notepad.exe eltiempo.txt" )
     
     leejson( cResp )
   Catch
      MsgStop( "Error" )
      Return cResp
   End Try


Return nil

//------------------------------------------------------------------------------

function Leejson(cResp )
local hvar
local hvar1,hvar2
local cTexto:=""
local oDlg, cBmp
local nValor
local oBmp
local ofont1,ofont2

hb_jsondecode( cResp, @hvar )

hvar1:= hvar["query"]["results"]["channel"]

 define font ofont1 name "Arial" size 0,16 bold

 DEFINE Font ofont2 NAME "Verdana" SIZE 0,13 

 DEFINE DIALOG oDlg TITLE "Resultados" SIZE 500, 400 pixel color CLR_BLACK,CLR_WHITE
 
 
     @ 10 ,80 SAY alltrim(hvar1["title"] ) OF oDlg SIZE 180, 20 ;
                        pixel Font ofont1 color CLR_BLACK,CLR_WHITE 
     
     @ 25, 70 SAY "Fecha : "+ alltrim(hvar["query"]["created"])  SIZE 180, 20 OF oDlg ;
                    pixel  color CLR_BLACK,CLR_WHITE FONT ofont2
               
     hvar2:= hvar1["wind"]
     
     @ 40, 100 say alltrim("Viento") SIZE 50, 20  OF oDlg  ;
                        pixel COLOR CLR_BLACK,CLR_WHITE FONT ofont1 
     @ 50, 50 say alltrim("Sensacion Termica :" )  OF oDlg ;
               pixel color CLR_BLACK,CLR_WHITE FONT ofont2 
     @ 50, 130 say alltrim( hVar2["chill"]+chr(186)+" "+ hvar1["units"]["temperature"] )  OF oDlg ;
              pixel color CLR_BLACK,CLR_WHITE FONT ofont2         
              
              
     @ 60, 50 say "Direcccion " OF oDlg ;
             pixel  color CLR_BLACK,CLR_WHITE FONT ofont2 
     @ 60, 130 say  hVar2["direction"]  OF oDlg ;
             pixel  color CLR_BLACK,CLR_WHITE FONT ofont2         
             
     @ 70, 50 say "Velocidad "  OF oDlg ;
                     pixel  color CLR_BLACK,CLR_WHITE FONT ofont2 
     
     @ 70, 130 say  hVar2["speed"]+" "+ hvar1["units"]["speed"]  OF oDlg ;
                     pixel  color CLR_BLACK,CLR_WHITE FONT ofont2 
     
          
        hvar2:= hvar1["atmosphere"]
      
     @ 85, 95 say "Atmosfera " OF oDlg ;
                      pixel  color CLR_BLACK,CLR_WHITE FONT ofont1 
                      
     @ 100, 50 say "Humedad " OF oDlg ;
                    pixel  color CLR_BLACK,CLR_WHITE FONT ofont2 
     @ 100, 130 say  hVar2["humidity"] + " %" OF oDlg ;
                    pixel  color CLR_BLACK,CLR_WHITE FONT ofont2 
                                        
                    
     @ 110, 50 say "Presion Barometrica " OF oDlg ;
                        pixel   color CLR_BLACK,CLR_WHITE FONT ofont2 
                        
     @ 110, 130 say hVar2["pressure"] + " "+ hvar1["units"]["pressure"] OF oDlg ;
                        pixel   color CLR_BLACK,CLR_WHITE FONT ofont2 
                                            
     
     nValor:= hVar2["rising"] 
      
     if  nValor == "0"
         cTexto := "Estable"
     elseif nValor == "1"
         cTexto := "Subiendo"
     elseif nValor == "2"   
         cTexto := "Bajando"
     endif
        
     @ 120, 50 say "Tendencia Barometrica: "  OF oDlg ;
                        pixel color CLR_BLACK,CLR_WHITE FONT ofont2 
     @ 120, 130 say cTexto OF oDlg ;
                        pixel color CLR_BLACK,CLR_WHITE FONT ofont2 
     
      hvar2:= hvar1["astronomy"]
     
     
     
     @ 160, 30 say "Orto " + hVar2["sunrise"] OF oDlg ;
                         pixel color CLR_BLACK,CLR_WHITE FONT ofont2 
                         
     @ 160, 160 say "Ocaso " + hVar2["sunset"] OF oDlg ;
                         pixel color CLR_BLACK,CLR_WHITE FONT ofont2 
  
      hvar2:= hvar1["item"] 
     
          
      cTexto:=hVar2["condition"]["code"]
      
      cTexto:="http://l.yimg.com/a/i/us/we/52/"+cTexto+".gif"    
        
     @ 10,12  IMAGE oBmp FILE cBmp OF oDlg size 32,32 pixel NOBORDER
         
      cargaBmp(cTexto,oBmp)
         
    @ 184, 100 BUTTON "&Ok" SIZE 40, 12  OF oDlg pixel ;
      ACTION odlg:end() FONT oFont2
   
 ACTIVATE DIALOG oDlg CENTERED on paint ( cargaBmp(cTexto,obmp), DlgStatusBar(oDlg, 68,, .t. )  )
  
  ofont1:end()
  ofont2:end()  

 return nil

//------------------------------------------------------------------------------

Function DlgStatusBar(oDlg, nHeight, nCorrec , lColor )
Local nDlgHeight := oDlg:nHeight
Local aColor     := { { 0.40, nRGB( 200, 200, 200 ), nRGB( 184, 184, 184 ) },;
                    { 0.60, nRGB( 184, 184, 184 ), nRGB( 150, 150, 150 ) } }

DEFAULT nHeight  := 72
DEFAULT nCorrec  := 0
DEFAULT lColor   := .F.

nDlgHeight:= nDlgHeight+ncorrec
IF lColor
   GradienTfill(oDlg:hDC,nDlgHeight-( nHeight-2 ),0,nDlgHeight-20,oDlg:nWidth, aColor ,.t.)
   WndBoxIn( oDlg:hDc,nDlgHeight-( nHeight-1 ),0,nDlgHeight-( nHeight ),oDlg:nWidth )
ELSE
   WndBoxIn( oDlg:hDc,nDlgHeight -( nHeight-1 ),4,nDlgHeight-( nHeight ),oDlg:nWidth - 10 )
endif

Return Nil

//------------------------------------------------------------------------------

FUNCTION DlgBarTitle( oWnd, cTitle, cBmp ,nHeight )
   LOCAL oFont
   LOCAL oTitle
   LOCAL nColText := 180
   LOCAL nRowImg  := 0
   

   DEFAULT cTitle  := ""
   DEFAULT nHeight := 48

   IF nHeight < 48
      nColText := 60
      nRowImg  := 12
      DEFINE FONT oFont NAME "Arial" size 10, 30
   ELSE
      DEFINE FONT oFont NAME "Arial" size 12, 30
   endif

    @ -1, -1  TITLE oTitle size oWnd:nWidth+1, nHeight+1 of oWnd SHADOWSIZE 0
   
   @  nRowImg,  10  TITLEIMG  OF oTitle BITMAP cBmp  SIZE 48, 48 REFLEX ;
          TRANSPARENT
   
    @  nRowImg-2 ,  nColText TITLETEXT OF oTitle TEXT cTitle COLOR CLR_BLACK FONT oFont

    oTitle:aGrdBack := { { 1, RGB( 255, 255, 255 ), RGB( 229, 233, 238 )  } }
    oTitle:nShadowIntensity = 0
    oTitle:nShadow = 0
    oTitle:nClrLine1 := nrgb(0,0,0)
    oTitle:nClrLine2 := RGB( 229, 233, 238 )
    oWnd:oTop:= oTitle
          

RETURN oTitle
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: un pequeño ejemplo ...meteo.prg
Posted: Mon Dec 08, 2014 06:40 PM

Gracias distinguido por compartir.

Sólo faltaría hacerlo funcionar con PROXY.

Saludos,

Adhemar

Saludos,



Adhemar C.
Posts: 555
Joined: Wed Jul 31, 2013 01:14 PM
Re: un pequeño ejemplo ...meteo.prg
Posted: Mon Dec 08, 2014 07:15 PM

Imponente, gracias.

Dario Fernandez

FWH 2501, Harbour, MVS2022 Community, MySql & MariaDB, Dbf/Cdx VSCode.

Maldonado - Uruguay
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: un pequeño ejemplo ...meteo.prg
Posted: Mon Dec 08, 2014 07:24 PM
acuellar wrote:Gracias distinguido por compartir.

Sólo faltaría hacerlo funcionar con PROXY.

Saludos,

Adhemar


Seria ( en teoria ) añadir estas dos lineas en las dos llamadas a ohttp ...no lo he probado pero si tu tienes proxi agradecería me comentaras si funciona .

Code (fw): Select all Collapse
cProxi:= "192.10.1.1:8080" // tu configuracion proxi .  

 oHttp := CreateObject("winhttp.winhttprequest.5.1")

 oHttp:SetProxy( HTTPREQUEST_PROXYSETTING_PROXY,cProxi  )  // linea nueva

 oHttp:Open("GET", cDir, .f. )
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: un pequeño ejemplo ...meteo.prg
Posted: Mon Dec 08, 2014 10:11 PM
Ya hice los cambios indicados y no funciona

Code (fw): Select all Collapse
Try
      cProxi:= "192.10.1.7:8080"
      oHttp := CreateObject("winhttp.winhttprequest.5.1")
      oHttp:SetProxy( HTTPREQUEST_PROXYSETTING_PROXY,cProxi  )
      oHttp:Open("GET", cDir, .f. )
      oHttp:Send()
      cResp := oHttp:ResponseText()
        
     leejson( cResp )
   Catch
      MsgStop( "Error al cargar el tiempo" )
      Return cResp
   End Try


Saludos,

Adhemar
Saludos,



Adhemar C.
Posts: 518
Joined: Fri Jun 29, 2012 12:49 PM
Re: un pequeño ejemplo ...meteo.prg
Posted: Tue Dec 09, 2014 07:15 AM

Gracias Manuel!!!

Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: un pequeño ejemplo ...meteo.prg
Posted: Tue Dec 09, 2014 08:42 AM

Adhemar.

¿ Has declarado el valor de HTTPREQUEST_PROXYSETTING_PROXY ?

define HTTPREQUEST_PROXYSETTING_PROXY 2

si con eso no funciona ....

¿ Poniendo los ajustes del proxi asi ? :

para el archivo json :
oHttp:SetProxy( HTTPREQUEST_PROXYSETTING_PROXY, "proxy_server:80" , "*.yahooapis.com" )

y para la imagen :
oHttp:SetProxy( HTTPREQUEST_PROXYSETTING_PROXY, "proxy_server:80" , "*.yimg.com" )

Posts: 728
Joined: Fri Oct 07, 2005 07:38 AM
Re: un pequeño ejemplo ...meteo.prg
Posted: Tue Dec 09, 2014 09:11 AM

Se ve excelente, gracias!

Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: un pequeño ejemplo ...meteo.prg
Posted: Tue Dec 09, 2014 04:17 PM
Gracias Manuel

Con solo declarar
Code (fw): Select all Collapse
# define HTTPREQUEST_PROXYSETTING_PROXY 2


Funcionó perfecto.

Cómo sería para obtener la mínima y la máxima del día??

Saludos,

Adhemar
Saludos,



Adhemar C.
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: un pequeño ejemplo ...meteo.prg
Posted: Tue Dec 09, 2014 05:14 PM
Se puede acomodar la prevision de varios dias .... lo pongo a lo feo , seria bueno hacerlo "bonito" ...
el primer dia es el presente y da la maxinma y la mínima .

Code (fw): Select all Collapse
  hvar2:= hvar1["item"] 
      
       // codigo nuevo insertado despues de "item" 
  
     aHTexto:=hVar2["forecast"]
    
     for i=1 to len(aHTexto)
     
          hDias:=aHTexto[i] 
          
         cTexto:= "Fecha: " + hDias["date"] +CRLF
         cTexto+= "Dia  : " + hDias["day"] +CRLF 
         cTexto+= "Maxima: " + hDias["high"] +CRLF 
         cTexto+= "Minima: " + hDias["low"] +CRLF  
         cTexto+= "Prevision:" + hDias["text"] +CRLF  
         cTexto+= "Codigo de imagen :" + hDias["code"] +CRLF  
         
         msginfo( cTexto ) 
     next
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: un pequeño ejemplo ...meteo.prg
Posted: Tue Dec 09, 2014 05:23 PM

thanks Manuel,
two questions ...

how I can control ( on the test) if I must use proxy or not ?

for the week status we can use xbrowse as array but I not found the possibility how show the image

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: un pequeño ejemplo ...meteo.prg
Posted: Tue Dec 09, 2014 05:25 PM
it return a code :

Code (fw): Select all Collapse
Code    Description
0   tornado
1   tropical storm
2   hurricane
3   severe thunderstorms
4   thunderstorms
5   mixed rain and snow
6   mixed rain and sleet
7   mixed snow and sleet
8   freezing drizzle
9   drizzle
10  freezing rain
11  showers
12  showers
13  snow flurries
14  light snow showers
15  blowing snow
16  snow
17  hail
18  sleet
19  dust
20  foggy
21  haze
22  smoky
23  blustery
24  windy
25  cold
26  cloudy
27  mostly cloudy (night)
28  mostly cloudy (day)
29  partly cloudy (night)
30  partly cloudy (day)
31  clear (night)
32  sunny
33  fair (night)
34  fair (day)
35  mixed rain and hail
36  hot
37  isolated thunderstorms
38  scattered thunderstorms
39  scattered thunderstorms
40  scattered showers
41  heavy snow
42  scattered snow showers
43  heavy snow
44  partly cloudy
45  thundershowers
46  snow showers
47  isolated thundershowers
3200    not available




for a sample :




https://s.yimg.com/zz/combo?a/i/us/we/52/28.gif
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: un pequeño ejemplo ...meteo.prg
Posted: Tue Dec 09, 2014 05:52 PM
I'm thinkg so:
Local aforecast:= array(7,6)

aHTexto:=hVar2["forecast"]

for i=1 to len(aHTexto)

hDias:=aHTexto[i]

cData:= hDias["date"]
cDay:= hDias["day"]
cMax:= str(hDias["high"] )
cMin:= str(hDias["low"] )
cPrev:= hDias["text"]
cImage:="http://l.yimg.com/a/i/us/we/52/"+hDias["code"]+".gif"

AaDd(aForecast[i],{cData,cDay,cMax,cMin,cPrev,cImage})

next

but there is something no run
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: un pequeño ejemplo ...meteo.prg
Posted: Tue Dec 09, 2014 05:56 PM

Perfecto.

Gracias Manuel.

Saludos,

Adhemar

Saludos,



Adhemar C.
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: un pequeño ejemplo ...meteo.prg
Posted: Tue Dec 09, 2014 06:04 PM
Silvio , necesitas recoger las imagenes de internet .
Tienes dos formas :
1.- grabar imagen en un temp
2.- cargarlas sobre la marcha.
Cuidado con los tiempos de carga de las imagenes , tienes que dar timepo a que se cogan de internet o fallará.
Code (fw): Select all Collapse
Function loadBmp(cUrl)
local oHttp
local cResp := nil

   Try
      oHttp := CreateObject( "winhttp.winhttprequest.5.1" )
      oHttp:Open("GET", cUrl, .f. )
      oHttp:Send()
      cResp := oHttp:ResponseBody()
      memowrit( "cResp, "temp1.img")
        Catch
      MsgStop( "Error" )
      Return cResp
   End Try
  
Return cResp