#include "FiveWin.ch"
function Main()
local cPost := "f=6&t=42239&sid=4290062a3f768e4ee2ba52d66b669097#p253728"
FW_memoEdit( WebPageContents( "https://fivetechsupport.com/forums/viewtopic.php?http://fivetechsupport.com/forums/viewtopic.php?" + ;
cPost ) )
return nil
#include "FiveWin.ch"
function Main()
local cPost := "f=6&t=42239&sid=4290062a3f768e4ee2ba52d66b669097#p253728"
Local cZoeksub1_start,cZoeksub1_end
Local cZoeksub1_strip_link_start := 'a href="/'
Local cZoeksub1_strip_link_end := '"'
Local cText, cTemp, cTempSub
Local nSubmenu
Local aData:={}
FW_memoEdit( WebPageContents( "https://fivetechsupport.com/forums/viewtopic.php?http://fivetechsupport.com/forums/viewtopic.php?" + cPost ) )
cText = WebPageContents( "https://fivetechsupport.com/forums/viewtopic.php?http://fivetechsupport.com/forums/viewtopic.php?" + cPost )
cText = strtran(cText,"<br />",CRLF)
cZoeksub1_start := 'id="p253728"'
cZoeksub1_end := '"divider"'
cText = textertussen( cText, cZoeksub1_start,cZoeksub1_end, 1 )
// Topic selected
cZoeksub1_start := '"#p253728"'
cZoeksub1_end := '</a>'
ctempSub = textertussen( cText, cZoeksub1_start,cZoeksub1_end, 1 )
// Auther
cZoeksub1_start := 'coloured">'
cZoeksub1_end := '</a>'
ctempSub = textertussen( cText, cZoeksub1_start,cZoeksub1_end, 1 )
aadd(aData,"Author : "+cTempSub)
// Date
cZoeksub1_start := 'raquo;'
cZoeksub1_end := '</p>'
ctempSub = textertussen( cText, cZoeksub1_start,cZoeksub1_end, 1 )
aadd(aData,"Date : "+cTempSub)
// Content
cZoeksub1_start := '"content">'
cZoeksub1_end := '<dl class'
ctempSub = textertussen( cText, cZoeksub1_start,cZoeksub1_end, 1 )
aadd(aData,"Content : "+cTempSub)
// Source code
//cZoeksub1_start := 'Expand view'
cZoeksub1_start := '00D7D7;">' // This color seems to be always there
cZoeksub1_end := '</code>'
ctempSub = textertussen( cText, cZoeksub1_start,cZoeksub1_end, 1 )
aadd(aData,"Source 1 : "+cTempSub)
// Trim the source from HTML code
ctempSub = strtran(ctempSub,"</span>","")
aadd(aData,"Source 2: "+cTempSub)
// More trimming needed
xbrowser(aData)
return nil
function Textertussen( cText, cStartTag, cCloseTag, nPos, cLeft, cRight )
local cRet := ""
if !( cStartTag $ cText )
cLeft := cText
cRight := ""
return ""
endif
cRight := AfterAtNum( cStartTag, cText, nPos )
cRet := BeforAtNum( cCloseTag, cRight, 1 )
if PCount() > 4
cLeft := BeforAtNum( cStartTag, cText, nPos )
cRight := AfterAtNum( cCloseTag, cRight, 1 )
endif
return cRet
#include "FiveWin.ch"
function Main()
// link for second test
//local cPost := "f=6&t=42239&sid=4290062a3f768e4ee2ba52d66b669097#p253728"
local cPost := "f=3&t=42249&sid=844b9e3e8d8f3961169850370d02d06b#p253781"
Local cZoeksub1_start,cZoeksub1_end
Local cZoeksub1_strip_link_start := 'a href="/'
Local cZoeksub1_strip_link_end := '"'
Local cText, cTemp, cTempSub, cData
Local nSubmenu, nTel:=1
Local aData:={}
// See content
cText = WebPageContents( "https://fivetechsupport.com/forums/viewtopic.php?http://fivetechsupport.com/forums/viewtopic.php?" + cPost )
FW_memoEdit(cText)
cText = strtran(cText,"<br />",CRLF)
//cZoeksub1_start := 'id="p253728"'
cZoeksub1_start := 'id="p253781"'
cZoeksub1_end := '"divider"'
cText = textertussen( cText, cZoeksub1_start,cZoeksub1_end, 1 )
// Topic selected
//cZoeksub1_start := 'id="p253728"'
cZoeksub1_start := '"#p253781"'
cZoeksub1_end := '</a>'
ctempSub = textertussen( cText, cZoeksub1_start,cZoeksub1_end, 1 )
// Auther
cZoeksub1_start := 'coloured">'
cZoeksub1_end := '</a>'
ctempSub = textertussen( cText, cZoeksub1_start,cZoeksub1_end, 1 )
aadd(aData,"Author : "+cTempSub)
// Date
cZoeksub1_start := 'raquo;'
cZoeksub1_end := '</p>'
ctempSub = textertussen( cText, cZoeksub1_start,cZoeksub1_end, 1 )
aadd(aData,"Date : "+cTempSub)
// Content
cZoeksub1_start := '"content">'
cZoeksub1_end := '<dl class'
ctempSub = textertussen( cText, cZoeksub1_start,cZoeksub1_end, 1 )
aadd(aData,"Content : "+cTempSub)
// Source code
cZoeksub1_start := '00D7D7;">' // This color seems to be always there
cZoeksub1_end := '</code>'
ctempSub = textertussen( cText, cZoeksub1_start,cZoeksub1_end, 1 )
aadd(aData,"Source 1 : "+cTempSub)
// Trim the source from HTML code
ctempSub = strtran(ctempSub,"</span>","")
aadd(aData,"Source 2: "+cTempSub)
// Clean more HTML code that is more than once in de code
cZoeksub1_start := '<' // This color seems to be always there
cZoeksub1_end := '>'
do while .t.
nTel++
if nTel > 100 // In case of endless loop
exit
endif
if at("<",cTempSub) > 0 .and. at(">",cTempSub) > 0
cData = textertussen( ctempSub, cZoeksub1_start,cZoeksub1_end, 1 )
if !empty(cData)
ctempsub = strtran(ctempsub,cData,"")
ctempsub = strtran(ctempsub,"<>","")
endif
else
exit
endif
enddo
do while at("(",ctempsub) > 0
ctempsub = strtran(ctempsub,"(","(")
enddo
do while at(")",ctempsub) > 0
ctempsub = strtran(ctempsub,")",")")
enddo
cZoeksub1_start := '#'
cZoeksub1_end := ';'
do while .t.
nTel++
if nTel > 100 // In case of endless loop
exit
endif
if at("#",cTempSub) > 0 .and. at(";",cTempSub) > 0
cData = textertussen( ctempSub, cZoeksub1_start,cZoeksub1_end, 1 )
if !empty(cData)
ctempsub = strtran(ctempsub,cData,"")
ctempsub = strtran(ctempsub,"#;","")
endif
else
exit
endif
enddo
do while at(""",ctempsub) > 0
ctempsub = strtran(ctempsub,""","")
enddo
do while at(" ",ctempsub) > 0
ctempsub = strtran(ctempsub," ","")
enddo
do while at("&&",ctempsub) > 0
ctempsub = strtran(ctempsub,"&&","")
enddo
do while at("&&",ctempsub) > 0
ctempsub = strtran(ctempsub,"&&","")
enddo
aadd(aData,"Source 3 : "+CRLF+CRLF+cTempSub)
xbrowser(aData)
msginfo(cTempSub)
return nil
function Textertussen( cText, cStartTag, cCloseTag, nPos, cLeft, cRight )
local cRet := ""
if !( cStartTag $ cText )
cLeft := cText
cRight := ""
return ""
endif
cRight := AfterAtNum( cStartTag, cText, nPos )
cRet := BeforAtNum( cCloseTag, cRight, 1 )
if PCount() > 4
cLeft := BeforAtNum( cStartTag, cText, nPos )
cRight := AfterAtNum( cCloseTag, cRight, 1 )
endif
return cRet
Marc Venken wrote:In the download is only the exe file ?
Antonio Linares wrote:Dear Marc,
DO EVENTS in FWH is SysRefresh()
Marc Venken wrote:I get stuck op the Do EVENTS, Set property, do method that seems to be external ?
DO Events -> SysRefresh()
GetPropertry(oWin, oControl,xValue) -> get xValue of cControl in oWin
SetPropertry(oWin, oControl,xValue, 123) -> Set xValue of cControl in oWin
DoMethod( oWin, oControl, xMethod ) -> use Method of cControl in oWin
SetProperty( "TranslateMemo", "RichEdit_Translate", "Value", TRIM( cTranslated ) )
DoMethod( "TranslateMemo", "RichEdit_Translate", "Refresh" )
OleSetProperty()
OLEInvoke()
*+--------------------------------------------------------------------
*+
*+ Procedure TranslateByGoogle()
*+
*+ Called from ( forumhmg.prg ) 1 - static procedure forum_store()
*+ ( translat.prg ) 1 - procedure translatememoform()
*+ 1 - static procedure oninittranslate()
*+ Source = Jimmy from FW-Forum
*+--------------------------------------------------------------------
*+
PROCEDURE TranslateByGoogle()
LOCAL cTargetLang := "NL"
LOCAL cSourceLang := "auto" // default
LOCAL cSampleText
LOCAL cSourceText
LOCAL cGTUrl
LOCAL hResp, nTry, i, nHttpError, cErrorDesc
LOCAL cTranslated := ""
LOCAL cOryginal := ""
LOCAL cLangDetect := ""
LOCAL oHTTP, oErr, nReadystate, nStatus
LOCAL cTest:="This is a test for translation"
BEGIN SEQUENCE WITH { | o | BREAK( o ) }
oHTTP := Win_OleCreateObject( "MSXML2.ServerXMLHTTP" )
RECOVER
END SEQUENCE
IF EMPTY( oHTTP )
RETURN
ENDIF
cSampleText := TRIM( cTest )
cSourceText := hb_StrToUTF8( cSampleText )
cGTUrl := "https://translate.googleapis.com/translate_a/single?client=gtx" + ;
"&sl=" + cSourceLang + ;
"&tl=" + cTargetLang + ;
"&dt=t&q=" + tip_URLEncode( cSourceText )
BEGIN SEQUENCE WITH { | o | BREAK( o ) }
oHTTP:Open( "POST", cGTUrl, .F. )
oHTTP:SetRequestHeader( "Content-Type", "application/x-www-form-urlencoded" )
nTry := 0
DO WHILE oHTTP:readyState = 0
nTry ++
millisec( 500 )
sysrefresh()
IF nTry > 5
BREAK
ENDIF
ENDDO
oHTTP:Send()
nReadystate := oHttp:readyState
IF nReadystate <> 4
BREAK
ENDIF
nStatus := oHttp:Status
IF nStatus = 200
IF HB_jsonDecode( oHTTP:responseText, @hResp ) > 0
cLangDetect := hResp[ 3 ]
FOR i := 1 TO LEN( hResp[ 1 ] )
cTranslated += hResp[ 1 ] [ i ] [ 1 ]
cOryginal += hResp[ 1 ] [ i ] [ 2 ]
NEXT i
ENDIF
ELSE
BREAK
ENDIF
MsgInfo ("To translate: " + cOryginal + CRLF + CRLF + ;
"Translated: " + cTranslated + CRLF + CRLF + ;
"Language: " + cLangDetect )
//SetProperty( "TranslateMemo", "RichEdit_Translate", "Value", TRIM( cTranslated ) )
//DoMethod( "TranslateMemo", "RichEdit_Translate", "Refresh" )
RECOVER USING oErr
IF nStatus = 429
lTranslate := .F.
MsgStop( 'too many requests in a given amount of time ("rate limiting")' )
ELSE
nHttpError := IF( oHttp:readyState > 1, oHTTP:status, IF( oErr == Nil, - 1, oErr:SubCode ) )
cErrorDesc := IF( oErr == Nil, "None descripion", hb_Translate( oErr:Description, "DEWIN" ) )
MsgStop( " Error " + cErrorDesc + " ( " + STR( nHttpError ) + " )" )
ENDIF
END SEQUENCE
oHTTP:Abort()
oHTTP := NIL
RETURN
Marc Venken wrote:Restarting the program resets the Google timer for the request right ?
Marc Venken wrote:How many request are possible in free mode ?
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 101 guests