New Version
This release is complete of Finance and Meteo Yahoo ( with or without Proxy)
I add a main dialog to call finance and Meteo services yahoo
Make a folder
Yahoo and insert this sources
the include on includes folder
YaHoo.prg
#include "FiveWin.ch"
#include "constant.ch"
Function Yahoo()
Local oDlgYahoo,oFont
Local nBottom := 14
Local nRight := 55
Local nWidth := Max( nRight * DLG_CHARPIX_W, 180 )
Local nHeight := nBottom * DLG_CHARPIX_H
Local oBtnOption[2]
local cUrl_Finance := "http://eur.i1.yimg.com/eur.yimg.com/i/it/fi/fi6.gif"
local cUrl_Meteo := "http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"
Local oBmpMeteo,cBmpMeteo
Local oBmpFinance,cBmpFinance
lProxy:=Request_Proxy()
If lProxy
cSection :="Config"
cIniFile := cFilePath(GetModuleFileName( GetInstance() ) ) + PROXY_MEM
PROXY_SCHOOL := GetIni(cIniFile, cSection, "Proxy")
NPORT := val(GetIni(cIniFile, cSection, "Port"))
USERNAME := GetIni(cIniFile, cSection, "Username")
PASSWORD := GetIni(cIniFile, cSection, "Password")
Endif
DEFINE FONT oFont NAME "MS Sans Serif" SIZE 0, 8
DEFINE DIALOG oDlgYahoo TITLE "Yahoo" ;
FROM 100, 100 TO 230,600 pixel
@ 0,10 IMAGE oBmpMeteo FILE cBmpMeteo OF oDlgYahoo size 142,35 pixel NOBORDER ON CLICK Meteo()
@ 40,10 IMAGE oBmpFinance FILE cBmpFinance OF oDlgYahoo size 142,35 pixel NOBORDER ON CLICK Finance()
oBmpMeteo:lTransparent := .t.
oBmpFinance:lTransparent := .t.
cargaBmp(cUrl_Meteo,oBmpMeteo,lProxy)
cargaBmp(cUrl_Finance,oBmpFinance,lProxy)
ACTIVATE DIALOG oDlgYahoo CENTERED
return nil
Proxy.prg
#include "FiveWin.ch"
#include "ttitle.ch"
#include "constant.ch"
#include ".\INCLUDE\yahoo.ch"
// to connect to Internet without or With Proxy
Function Request_Proxy()
Local lReturn
IF MsgyesNo("Devo usare il proxy ?")
lReturn :=.t.
Valid_Proxy()
else
lReturn :=.f.
endif
return lReturn
//------------------------------------------------------------------------------//
Function Valid_Proxy()
Local oDlgProxy,oFont
Local cIniFile := cFilePath(GetModuleFileName( GetInstance() ) ) + PROXY_MEM
Local nBottom := 14
Local nRight := 55
Local nWidth := Max( nRight * DLG_CHARPIX_W, 180 )
Local nHeight := nBottom * DLG_CHARPIX_H
Local oBtnHelp,oBtnOK,oBtnCan
Local cUSERNAME := pad(GetPvProfString("Config","Username" ,"mioUsername" ,cIniFile ) , 40 ," " )
Local cPASSWORD := pad(GetPvProfString("Config","Password" ,"miapassword" ,cIniFile ) , 40 ," " )
Local cPROXY := pad(GetPvProfString("Config","Proxy" ,"miaproxy" ,cIniFile ) , 45 ," " )
Local nPORT := pad(GetPvProfString("Config","Port" ,"8080" ,cIniFile ) , 4 ," " )
Local aGet[4]
DEFINE FONT oFont NAME "MS Sans Serif" SIZE 0, 8
DEFINE DIALOG oDlgProxy TITLE "Validate Proxy" ;
FROM 100, 100 TO 230,600 pixel
@ 12, 10 SAY "Proxy:" OF oDlgProxy SIZE 60, 8 PIXEL FONT oFont
@ 10, 45 GET aGet[1] VAR cPROXY OF oDlgProxy SIZE 50, 12 PIXEL FONT oFont
@ 26, 10 SAY "Port:" OF oDlgProxy SIZE 80, 8 PIXEL FONT oFont
@ 24, 45 GET aGet[2] var nPORT OF oDlgProxy SIZE 44, 12 PIXEL FONT oFont
@ 12, 120 SAY "Username:" OF oDlgProxy SIZE 80, 8 PIXEL FONT oFont
@ 10, 175 GET aGet[3] var cUSERNAME OF oDlgProxy SIZE 44, 12 PIXEL FONT oFont
@ 26, 120 SAY "Password:" OF oDlgProxy SIZE 80, 8 PIXEL FONT oFont
@ 24, 175 GET aGet[4] var cPASSWORD OF oDlgProxy SIZE 44, 12 PIXEL FONT oFont
@ 46, 4 BUTTON oBtnHelp PROMPT "&Help" OF oDlgProxy SIZE 42, 12 PIXEL FONT oFont ACTION Helpindex()
@ 46, 160 BUTTON oBtnOK PROMPT I18n("Confirm") OF oDlgProxy SIZE 42, 12 PIXEL FONT oFont DEFAULT ACTION (oDlgProxy:End(IDOK ))
@ 46, 204 BUTTON oBtnCan PROMPT i18n("Exit") OF oDlgProxy SIZE 42, 12 PIXEL FONT oFont CANCEL ACTION (oDlgProxy:End(IDCANCEL))
ACTIVATE DIALOG oDlgProxy CENTERED
if oDlgProxy:nresult == IDOK
SetIni( cInifile, "Config", "Proxy", cPROXY )
SetIni( cInifile, "Config", "Username", cUSERNAME )
SetIni( cInifile, "Config", "Password", cPASSWORD )
SetIni( cInifile, "Config", "Port", nPORT )
endif
return nil
ut_fun.prg
#include "FiveWin.ch"
#include "ttitle.ch"
FUNCTION SetIni( cIni, cSection, cEntry, xVar )
LOCAL oIni
DEFAULT cIni := oApp:cIniFile
INI oIni FILE cIni
SET SECTION cSection ;
ENTRY cEntry ;
TO xVar ;
OF oIni
ENDINI
RETURN nil
/*_____________________________________________________________________________*/
FUNCTION GetIni( cIni, cSection, cEntry, xDefault )
LOCAL oIni
LOCAL xVar := xDefault
DEFAULT cIni := oApp:cIniFile
INI oIni FILE cIni
GET xVar ;
SECTION cSection ;
ENTRY cEntry ;
DEFAULT xDefault ;
OF oIni
ENDINI
RETURN xVa
Function loadBmp(cUrl,lProxy)
local oHttp
local cResp := nil
cProxyNo := "*.yimg.com"
If lProxy
cSection :="Config"
cIniFile := cFilePath(GetModuleFileName( GetInstance() ) ) + "Meteo.ini"
PROXY_SCHOOL := GetIni(cIniFile, cSection, "Proxy")
NPORT := val(GetIni(cIniFile, cSection, "Port"))
USERNAME := GetIni(cIniFile, cSection, "Username")
PASSWORD := GetIni(cIniFile, cSection, "Password")
Endif
// ?PROXY_SCHOOL ,NPORT ,USERNAME ,PASSWORD
Try
oHttp := CreateObject( "winhttp.winhttprequest.5.1" )
if lProxy
oHttp:SetProxy( HTTPREQUEST_PROXYSETTING_PROXY, PROXY_SCHOOL+":"+alltrim(str(NPORT)))
endif
oHttp:Open("GET", cUrl, .f. )
if lProxy
oHttp:SetCredentials(USERNAME,PASSWORD,HTTPREQUEST_SETCREDENTIALS_FOR_PROXY)
endif
oHttp:Send()
cResp := oHttp:ResponseBody()
oHttp:WaitForResponse()
Catch
MsgStop( "Errore" )
Return cResp
End Try
Return cResp
Function cargaBmp(cUrl,oImage,lProxy)
local cResp := loadBmp(cUrl,lProxy)
local nZeroZeroClr
if !Empty( cResp )
// oImage:LoadFromString( cResp )
oImage:LoadFromMemory( cResp )
oImage:HasAlpha()
oImage:Refresh()
endif
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
Yahoo.ch
#define HTTPREQUEST_PROXYSETTING_DEFAULT 0
#define HTTPREQUEST_PROXYSETTING_PRECONFIG 0
#define HTTPREQUEST_PROXYSETTING_DIRECT 1
#define HTTPREQUEST_PROXYSETTING_PROXY 2
#define HTTPREQUEST_SETCREDENTIALS_FOR_SERVER 0
#define HTTPREQUEST_SETCREDENTIALS_FOR_PROXY 1
#define PROXY_MEM "proxy.ini"
Meteo.prg
Our first DialogBox sample
#include "FiveWin.ch"
#include "constant.ch"
#include ".\include\yahoo.ch"
Function Meteo()
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
local lProxy
Local cIniFile := cFilePath(GetModuleFileName( GetInstance() ) ) + PROXY_MEM
DEFINE Font ofont NAME "Verdana" SIZE 0,14
DEFINE ICON oIco FILE ".\Bitmaps\fivetech.ico"
lProxy:=Request_Proxy()
If lProxy
cSection :="Config"
cIniFile := cFilePath(GetModuleFileName( GetInstance() ) ) + PROXY_MEM
PROXY_SCHOOL := GetIni(cIniFile, cSection, "Proxy")
NPORT := val(GetIni(cIniFile, cSection, "Port"))
USERNAME := GetIni(cIniFile, cSection, "Username")
PASSWORD := GetIni(cIniFile, cSection, "Password")
Endif
// ?PROXY_SCHOOL
DEFINE DIALOG oDlg TITLE "Citt脿 da cercare" ;
ICON oIco SIZE 350, 240
@ 30,10 IMAGE oBmp FILE cBmp OF oDlg size 142,35 pixel NOBORDER
obmp:lTransparent := .t.
cargaBmp(cUrl,oBmp,lProxy)
// oBmp:display()
@ 60, 10 SAY "Introdurre la citta da trovare :" size 100, 12 ;
FONT oFont pixel OF oDlg
@ 70, 10 GET cCity size 120, 12 FONT oFont pixel OF oDlg
@ 105, 85 BUTTON "&Cerca" SIZE 40, 12 OF oDlg pixel ;
FONT oFont ;
ACTION llamada_meteo(cCity,lProxy)
@ 105,130 BUTTON "&Uscita" SIZE 40, 12 pixel OF oDlg;
FONT oFont ;
ACTION oDlg:End()
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT (DlgBarTitle( oDlg, " Servizio Metereologico",".\Bitmaps\weather.bmp" ,44 )) ;
ON PAINT DlgStatusBar(oDlg, 68,, .t. )
return nil
Function llamada_Meteo(cCity,lProxy)
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
If lProxy
cSection :="Config"
cIniFile := cFilePath(GetModuleFileName( GetInstance() ) ) + PROXY_MEM
PROXY_SCHOOL := GetIni(cIniFile, cSection, "Proxy")
NPORT := val(GetIni(cIniFile, cSection, "Port"))
USERNAME := GetIni(cIniFile, cSection, "Username")
PASSWORD := GetIni(cIniFile, cSection, "Password")
Endif
//?PROXY_SCHOOL ,NPORT ,USERNAME ,PASSWORD
Try
oHttp := CreateObject( "winhttp.winhttprequest.5.1" )
if lProxy
oHttp:SetProxy( HTTPREQUEST_PROXYSETTING_PROXY, PROXY_SCHOOL+":"+alltrim(str(NPORT)))
endif
oHttp:Open("GET", cDir, .f. )
if lProxy
oHttp:SetCredentials(USERNAME,PASSWORD,HTTPREQUEST_SETCREDENTIALS_FOR_PROXY)
endif
oHttp:Send()
*cResp := oHttp:ResponseBody()
cResp := oHttp:ResponseText()
oHttp:WaitForResponse()
leejson_Meteo( cResp,lProxy )
Catch
MsgStop( "Errore" )
Return cResp
End Try
Return cResp
/*
Try
oHttp := CreateObject("winhttp.winhttprequest.5.1")
oHttp:Open("GET", cDir, .f. )
oHttp:Send()
cResp := oHttp:ResponseText()
oHttp:WaitForResponse()
// memowrit("eltiempo.txt",cResp )
// msginfo("grabado")
// winexec( "notepad.exe eltiempo.txt" )
leejson_Meteo( cResp )
Catch
MsgStop( "Error" )
Return cResp
End Try
*/
Return nil
//------------------------------------------------------------------------------
function Leejson_Meteo(cResp ,lProxy)
local hvar
local hvar1,hvar2
local cTexto:=""
local oDlg, cBmp
local nValor
local oBmp
local ofont1,ofont2
Local oBrwForecast
local i
local cImage,cMin,cMax,cData,cDay
local ahTexto,hDias,cPrev
local cUrl
local oBmp2,cBmp2
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 "Risultati" SIZE 600, 600 pixel color CLR_BLACK,CLR_WHITE
@ 10 ,80 SAY alltrim(hvar1["title"] ) OF oDlg SIZE 100, 10 ;
pixel Font ofont1 color CLR_BLACK,CLR_WHITE
@ 25, 70 SAY "Data : "+ alltrim(hvar["query"]["created"]) SIZE 100, 10 OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
hvar2:= hvar1["wind"]
@ 40, 100 say alltrim("Vento") SIZE 50, 20 OF oDlg ;
pixel COLOR CLR_BLACK,CLR_WHITE FONT ofont1
@ 50, 50 say alltrim("Sensazione 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 "Direzione " 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 "Velocit脿 " 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 "Umidit脿 " 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 "Pressione 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 := "Costante"
elseif nValor == "1"
cTexto := "In aumento"
elseif nValor == "2"
cTexto := "In diminuizione"
endif
@ 120, 50 say "Tendenza 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 "Alba " + hVar2["sunrise"] OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 160, 160 say "Tramonto " + hVar2["sunset"] OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
hvar2:= hvar1["item"]
aHTexto:=hVar2["forecast"]
nRow:=185
nCol:= 5
@ nRow,nCol say "Data" OF oDlg pixel color CLR_BLACK,CLR_WHITE FONT ofont2
nRow+= 8
@ nRow,nCol say "Giorno" OF oDlg pixel color CLR_BLACK,CLR_WHITE FONT ofont2
nRow+= 8
@ nRow,nCol say "Massima" OF oDlg pixel color CLR_BLACK,CLR_WHITE FONT ofont2
nRow+= 8
@ nRow,nCol say "Minimima" OF oDlg pixel color CLR_BLACK,CLR_WHITE FONT ofont2
nRow+= 8
@ nRow,nCol say "Previsione" OF oDlg pixel color CLR_BLACK,CLR_WHITE FONT ofont2
nCol+=45
nRow:=185
for i=1 to len(aHTexto)
hDias:=aHTexto[i]
cData:= hDias["date"]
cDay:= hDias["day"]
cMax:= hDias["high"]
cMin:= hDias["low"]
cPrev:= hDias["text"]
cUrl:= "http://l.yimg.com/a/i/us/we/52/"+hDias["code"]+".gif"
@ nRow,nCol say cData OF oDlg pixel color CLR_BLACK,CLR_WHITE FONT ofont2
nRow+= 8
@ nRow,nCol+15 say cDay OF oDlg pixel color CLR_BLACK,CLR_WHITE FONT ofont2
nRow+= 8
@ nRow,nCol+15 say cMax OF oDlg pixel color CLR_BLACK,CLR_WHITE FONT ofont2
nRow+= 8
@ nRow,nCol+15 say cMin OF oDlg pixel color CLR_BLACK,CLR_WHITE FONT ofont2
nRow+= 8
@ nRow,nCol say cPrev OF oDlg pixel color CLR_BLACK,CLR_WHITE FONT ofont2
nRow+= 10
@ nRow,nCol IMAGE oBmp FILE cBmp OF oDlg size 32,32 pixel NOBORDER
cargaBmp(cUrl,oBmp,lProxy)
nCol+=50
nRow:=185
next
@ 170, 2 GROUP oGroup TO 260,288 LABEL "Previsione settimanale" OF oDlg pixel TRANSPARENT
cUrl := "http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"
@ 10,189 IMAGE oBmp2 FILE cBmp2 OF oDlg size 142,55 pixel NOBORDER
obmp2:lTransparent := .t.
cargaBmp(cUrl,oBmp2,lProxy)
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,lProxy)
@ 285, 100 BUTTON "&Ok" SIZE 40, 12 OF oDlg pixel ;
ACTION odlg:end() FONT oFont2
ACTIVATE DIALOG oDlg CENTERED on paint DlgStatusBar(oDlg, 68,, .t. )
ofont1:end()
ofont2:end()
return nil
Finance.prg
// Our first DialogBox sample
#include "FiveWin.ch"
#include "ttitle.ch"
#include "constant.ch"
#include ".\yahoo.ch"
Function Finance()
local obmp ,cBmp
local oDlg, oIco ,cValor:= "BHP.AX"+space(20) // "GOOGL"+space(20) // "AAPL"+space(20)
local ofont
local cUrl :="http://eur.i1.yimg.com/eur.yimg.com/i/it/fi/fi6.gif"
local lProxy
Local cIniFile := cFilePath(GetModuleFileName( GetInstance() ) ) + PROXY_MEM
DEFINE Font ofont NAME "Verdana" SIZE 0,14
DEFINE ICON oIco FILE "c:\work\fwh\icons\fivewin.ico"
lProxy:=Request_Proxy()
If lProxy
cSection :="Config"
cIniFile := cFilePath(GetModuleFileName( GetInstance() ) ) + PROXY_MEM
PROXY_SCHOOL := GetIni(cIniFile, cSection, "Proxy")
NPORT := val(GetIni(cIniFile, cSection, "Port"))
USERNAME := GetIni(cIniFile, cSection, "Username")
PASSWORD := GetIni(cIniFile, cSection, "Password")
Endif
DEFINE DIALOG oDlg TITLE "Quote da ricercare" ;
ICON oIco SIZE 350, 240
@ 30,10 IMAGE oBmp FILE cBmp OF oDlg size 142,35 pixel NOBORDER
obmp:lTransparent := .t.
cargaBmp(cUrl,oBmp,lProxy)
@ 60, 10 SAY "Introduce el Valor a buscar :" size 100, 12 ;
FONT oFont pixel OF oDlg
@ 70, 10 GET cValor size 120, 12 FONT oFont pixel OF oDlg
@ 105, 85 BUTTON "&Buscar" SIZE 40, 12 OF oDlg pixel ;
FONT oFont ;
ACTION llamada_Finance(cValor,lProxy)
@ 105,130 BUTTON "&Salir" SIZE 40, 12 pixel OF oDlg;
FONT oFont ;
ACTION oDlg:End()
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT DlgBarTitle( oDlg, " Servicio Finaciero","c:\fwh\bitmaps\alphaBmp\weather.bmp" ,44 ) ;
ON PAINT DlgStatusBar(oDlg, 68,, .t. )
oFont:End()
return nil
static Function llamada_Finance(cValor,lProxy)
local oHttp
local cResp
local cDir
local Formato := "json"
cDir := "https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.quotes where symbol in ( '"+ cValor+ "')"
cDir := cDir + "&format="+ Formato +"®ion=ES"+"&lang=it-IT"+"&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback="
//cDir := cDir + "&format="+ Formato +"&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback="
//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= '"+ cValor +"' ) and u='"+cUnits+"'&format=" + Formato
If lProxy
cSection :="Config"
cIniFile := cFilePath(GetModuleFileName( GetInstance() ) ) + PROXY_MEM
PROXY_SCHOOL := GetIni(cIniFile, cSection, "Proxy")
NPORT := val(GetIni(cIniFile, cSection, "Port"))
USERNAME := GetIni(cIniFile, cSection, "Username")
PASSWORD := GetIni(cIniFile, cSection, "Password")
Endif
Try
oHttp := CreateObject( "winhttp.winhttprequest.5.1" )
if lProxy
oHttp:SetProxy( HTTPREQUEST_PROXYSETTING_PROXY, PROXY_SCHOOL+":"+alltrim(str(NPORT)))
endif
oHttp:Open("GET", cDir, .f. )
if lProxy
oHttp:SetCredentials(USERNAME,PASSWORD,HTTPREQUEST_SETCREDENTIALS_FOR_PROXY)
endif
oHttp:Send()
*cResp := oHttp:ResponseBody()
cResp := oHttp:ResponseText()
// memowrit("finance.txt",cResp )
leejson_Finance( cResp, cValor ,lProxy)
Catch
MsgStop( "Error" )
Return cResp
End Try
Return cResp
//------------------------------------------------------------------------------
Function Leejson_Finance(cResp,cValor ,lProxy)
local hvar
local hvar1,hvar2
local cTexto:=""
local oDlg, cBmp
local nValor
local oBmp
local ofont1,ofont2
Local oBrwForecast
local aForecast:= {}
local i
local cImage,cMin,cMax,cData,cDay
local ahTexto,hDias,cPrev
local cUrl
local nRow:=185
local nCol:= 5
local cTitle := "Resultados para el Valor: " + cValor
local cRegion:= "IT"
local cLang := "it-IT"
local aTipo :={ {"Line", "Bar", "Candle"},{ "l", "b", "c" } }
local aSize := { {"Large","Middle","Small"},{"l", "m", "s" } }
hb_jsondecode( cResp, @hvar )
hvar1:= hvar["query"]["results"]["quote"]
define font ofont1 name "Arial" size 0,16 bold
DEFINE Font ofont2 NAME "Verdana" SIZE 0,13
DEFINE DIALOG oDlg TITLE "Resultados" SIZE 500, 570 pixel color CLR_BLACK,CLR_WHITE
@ 10 ,80 SAY alltrim( cTitle ) 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
@ 50, 50 say alltrim("Valor :" ) OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 50, 130 say alltrim( hVar1["symbol"] ) OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 60, 50 say "Volumen Medio " OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 60, 130 say hVar1["AverageDailyVolume"] OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 70, 50 say "Demanda " OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 70, 130 say hVar1["AskRealtime"] OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 80, 50 say "Oferta " OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 80, 130 say hVar1["BidRealtime"] OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
// @ 85, 95 say "Atmosfera " OF oDlg ;
// pixel color CLR_BLACK,CLR_WHITE FONT ofont1
@ 100, 50 say "Ultimo Cambio " OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 100, 130 say hVar1["Change_PercentChange"] OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 110, 50 say "Maximo Anual " OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 110, 130 say hVar1["YearHigh"] OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 120, 50 say "Minimo Anual: " OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 120, 130 say hVar1["YearLow"] OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
cTexto:="http://chart.finance.yahoo.com/z?s=" + alltrim(cValor)+"&q="+aTipo[2,3] +"®ion="+cRegion+"&lang="+ cLang
cTexto:= cTexto+"&z=" + aSize[2,3]
@ 140,1 IMAGE oBmp FILE cBmp SIZE 248,124 OF oDlg ADJUST pixel NOBORDER
cargaBmp(cTexto,oBmp,lProxy)
@ 270, 100 BUTTON "&Ok" SIZE 40, 12 OF oDlg pixel ;
ACTION odlg:end() FONT oFont2
ACTIVATE DIALOG oDlg CENTERED on paint DlgStatusBar(oDlg, 68,, .t. )
ofont1:end()
ofont2:end()
return nil
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
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