Retrieve all my VFP posts on my Blog

Published on by Yousfi Benameur


At this time  31 december 2015 and after 11 busy months , i put 162 posts in my blogs desserving the vfp communauty.
I hope these codes bring some new things and highlight some dark areas.

this code retrieves all my posts in my blog begining with the most recent one (1 to  162 at this day).

-can fire any link to open a new window (see the javascript snippet to change the initial target window to _blank one and avoid some bad navigations in the initial window).
-Issue CTRL+F to search on the window any string.
the code use crawl method with xmlhttp and responsetext and build the page in temp folder.
i make 3 methods to view the final result(comment/uncomment one/3).


Important: code tested on win pro & VFP9SP2 and IE11 emulation.
run the code as administrator (vfp9.exe) to avoid some priveleges problems(always).
the codes i gave must be tested by vfp users and they must give some feedBacks to perform them or correct some typos.



Click on code to select [then copy] -click outside to deselect

 
 *1*
*important: execute vfp9.exe as administrator for avoiding some privelege problems.

************************************
Local npage,ystr,zstr,xx,uu,i,j,k,cTempFile,cURL
npage=27 &&to update
*************************************
Wait Window "nPage set in code to :"+Trans(npage)   Timeout 2
Declare Integer DeleteUrlCacheEntry In Wininet String
Local ystr
cTempFile=Addbs(Getenv("TEMP"))+"myoverblog"
Local oHTTP As "winhttp.winhttprequest.5.1"
Local cHTML
oHTTP=Newobject("winhttp.winhttprequest.5.1")
m.ystr=""

For i=1 To npage  &&27
    Try
		cURL="http://yousfi.over-blog.com/page/"+Trans(i)
		Wait Window cURL  Nowait
		oHTTP.Open("GET",cURL,.F.)
		oHTTP.Send()
		DeleteUrlCacheEntry(cURL) && delete the cached version
		Strtofile(oHTTP.ResponseText,cTempFile+Trans(i)+".html")
	Catch
	Endtry
Endfor

m.ystr=""
m.zstr=""
k=0
For i=1 To npage  
	Try
		cURL=cTempFile+Trans(i)+".html"

		Wait Window cURL  Nowait
		m.ystr=Filetostr(m.cURL)
		N=Occurs('<article class="post clearfix">',m.ystr)
		m.xx=""
		m.uu=""
		For j=1 To N
			m.k=m.k+1
			m.uu=Strextract(m.ystr,'<article class="post clearfix">','</article>',j,4)
			m.uu=Strtran(m.uu,"</time>"," - Post "+Trans(m.k)+"</time>")
			m.xx=m.xx+m.uu
		Endfor
		Wait Clea

		m.xx=m.xx+"<br><br>"+Chr(13)
		m.zstr=m.zstr+m.xx
	Catch
	Endtry
Endfor

m.zstr=Strtran(m.zstr,"</article>","</article></td> </tr><td>" )

TEXT to m.zstr textmerge noshow
<title>My posts in http://yousfi.over-blog.com -(<<trans(m.k)>>)</title>
<script>
function yb() {
var links = document.links;
for (var i = 0; i < links.length; i++) {
     links[i].target = "_blank";
}
}
</script>
<style>
body {background-color:black;padding:20px;}
p.snippet {background-color:bisque; color:maroon}
#table1 {background-color:bisque;}
</style>
<body "oncontextmenu="return false;"  onload="yb();">
<div >
<table style="width:100%;padding:10px;background-color:black;" ><tr>
<td><h2 style="color:red;">My posts in http://yousfi.over-blog.com -(<<trans(m.k)>>)</h2></td><td><h4 style="color:white;bold;float:right;font-size:small;"> issue CTRL+F to dialog search...</h4></td>
<td style="float:right;cursor:hand;"><img src="http://findicons.com/files/icons/2379/shopping/128/free_gift.png" width="48" height="48" onclick="alert('Happy new year2016   Yousfi Benameur');" ></td>
</tr>
</table>
</div>

<table id="table1" border="1" cellspacing="5">
<tr><td>
<<m.zstr>>
</tr></table>
</body>
ENDTEXT


ctempFileFinal=Addbs(Getenv("TEMP"))+"myoverblog_final.html"
Strtofile(m.zstr,ctempFileFinal)

For i=1 To npage
	Erase ( Addbs(Getenv("TEMP"))+"myoverblog"+Trans(i)+".html")
Endfor

*three methods to show the result (comment all+uncomment one)
*1)
Declare Integer BringWindowToTop In user32 Integer
DECLARE INTEGER ExtractIcon IN shell32 INTEGER hInst, STRING  lpszExeFileName, INTEGER lpiIcon
DECLARE INTEGER SendMessage IN user32 INTEGER hWnd, INTEGER Msg, INTEGER wParam, INTEGER lParam
DECLARE INTEGER SetWindowText IN user32 INTEGER hWnd, STRING lpString
*Constants for SendMessage second parameter
#DEFINE WM_GETICON 0x7F
#DEFINE WM_SETICON 0x80

*Constants for SendMessage third parameter
#DEFINE ICON_SMALL 0
#DEFINE ICON_BIG 1

local lnIcon
lnIcon = ExtractIcon (0,HOME(1)+"vfp9.exe",0)  && if exists on system


Local apie
apie=Newobject("internetexplorer.application")
With apie

	.menubar=0
	.Toolbar=0
	.StatusBar=0
	.Resizable=1
	.Width=800
	.Height=650
	.Top=(Sysmetric(2)-.Height)/2
	.Left=(Sysmetric(1)-.Width)/2
	.Navigate(m.ctempFileFinal)
	BringWindowToTop(.HWnd)
	SetWindowText(.HWND, "My vfp posts in Over-blog.com")
SendMessage(.HWND, WM_SETICON, ICON_small, lnIcon)

	.Visible=.T.
Endwith

*****
*!*    2)
*!*	Local yform
*!*	yform=Newobject("asup","","",m.cTempFileFinal)
*!*	yform.Show
*!*	Read Events
*!*	Retu

*!*	Define Class asup As Form
*!*		Height = 650
*!*		Width = 754
*!*		ShowWindow = 2
*!*		AutoCenter = .T.
*!*		minwidth=754
*!*		Caption = "My vfp posts in Over-blog.com"
*!*		Name = "Form1"

*!*		Add Object olecontrol1 As OleControl With ;
*!*			oleclass="shell.explorer.2",;
*!*			Top = 0, ;
*!*			Left = 0, ;
*!*			Height = 650, ;
*!*			Width = 757, ;
*!*			Anchor = 15, ;
*!*			Name = "Olecontrol1"

*!*		Procedure Init
*!*			Lparameters lcURL
*!*			If ! Pcount()=1
*!*				Return .F.
*!*			Endi
*!*			Thisform.olecontrol1.Navigate(lcURL)
*!*		Endproc

*!*		Procedure olecontrol1.Init
*!*			This.silent=.T.
*!*		Endproc

*!*		Procedure Destroy
*!*			Clea Events
*!*		Endproc

*!*	Enddefine

********
*3)
*!*	*can use this small code to view result
*!*	*local oo
*!*	*oo=newObject("hyperlink")
*!*	*oo.navigateTo(m.cTempFileFinal)
*!*	*oo=null

Retu

 

must update the pages number in code to make it refreshed.
must update the pages number in code to make it refreshed.
must update the pages number in code to make it refreshed.

must update the pages number in code to make it refreshed.

Click on code to select [then copy] -click outside to deselect


*2**How to search in my blog any string
*the search textbox on every page of my blog http://yousfi.over-blog.com/ is very performent an can be replaced successfully by a simple code below.

Local m.xsearched,m.ystr As String
m.xsearched=Inputbox("Any Searched string in yousfi.over-blog.com","","")

If !Empty(m.xsearched)
    m.ystr="http://yousfi.over-blog.com/search/"+m.xsearched+"/"
Endi

Local m.oo
m.oo=Newobject("hyperlink")
m.oo.NavigateTo(m.ystr)
m.oo=Null



To be informed of the latest articles, subscribe:
Comment on this post