un pequeño ejemplo ...meteo.prg

un pequeño ejemplo ...meteo.prg

Postby mastintin » Mon Dec 08, 2014 5: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: Select all  Expand view


// 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


 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: un pequeño ejemplo ...meteo.prg

Postby acuellar » Mon Dec 08, 2014 6:40 pm

Gracias distinguido por compartir.

Sólo faltaría hacerlo funcionar con PROXY.

Saludos,

Adhemar
Saludos,

Adhemar C.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: un pequeño ejemplo ...meteo.prg

Postby D.Fernandez » Mon Dec 08, 2014 7:15 pm

Imponente, gracias.
Dario Fernandez
FWH 22.12, Harbour, MVS2022 Community, BCC, MySql & MariaDB, Dbf/Cdx VSCode.
Maldonado - Uruguay
D.Fernandez
 
Posts: 455
Joined: Wed Jul 31, 2013 1:14 pm
Location: Maldonado - Uruguay

Re: un pequeño ejemplo ...meteo.prg

Postby mastintin » Mon Dec 08, 2014 7: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: Select all  Expand view

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. )

 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: un pequeño ejemplo ...meteo.prg

Postby acuellar » Mon Dec 08, 2014 10:11 pm

Ya hice los cambios indicados y no funciona

Code: Select all  Expand view

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.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: un pequeño ejemplo ...meteo.prg

Postby elvira » Tue Dec 09, 2014 7:15 am

Gracias Manuel!!!
elvira
 
Posts: 515
Joined: Fri Jun 29, 2012 12:49 pm

Re: un pequeño ejemplo ...meteo.prg

Postby mastintin » Tue Dec 09, 2014 8: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" )
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: un pequeño ejemplo ...meteo.prg

Postby AngelSalom » Tue Dec 09, 2014 9:11 am

Se ve excelente, gracias!
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 708
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España

Re: un pequeño ejemplo ...meteo.prg

Postby acuellar » Tue Dec 09, 2014 4:17 pm

Gracias Manuel

Con solo declarar
Code: Select all  Expand view

# 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.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: un pequeño ejemplo ...meteo.prg

Postby mastintin » Tue Dec 09, 2014 5: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: Select all  Expand view


  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


 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: un pequeño ejemplo ...meteo.prg

Postby Silvio.Falconi » Tue Dec 09, 2014 5: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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6796
Joined: Thu Oct 18, 2012 7:17 pm

Re: un pequeño ejemplo ...meteo.prg

Postby Silvio.Falconi » Tue Dec 09, 2014 5:25 pm

it return a code :

Code: Select all  Expand view
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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6796
Joined: Thu Oct 18, 2012 7:17 pm

Re: un pequeño ejemplo ...meteo.prg

Postby Silvio.Falconi » Tue Dec 09, 2014 5: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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6796
Joined: Thu Oct 18, 2012 7:17 pm

Re: un pequeño ejemplo ...meteo.prg

Postby acuellar » Tue Dec 09, 2014 5:56 pm

Perfecto.

Gracias Manuel.

Saludos,

Adhemar
Saludos,

Adhemar C.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: un pequeño ejemplo ...meteo.prg

Postby mastintin » Tue Dec 09, 2014 6: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: Select all  Expand view


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


User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Next

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 7 guests