Importing Posts Into Build My Rank

I realize that the following script is not going to be that useful to that many people, but if you are using iWriter to write your posts, are using BuildMyRank and also using ASP and want to import a lot of posts at the time then you may find it useful.

Not the neatest of code, but does the job and shouldn’t be hard to convert to PHP if needed.

Love to hear any comments as usual…

 

<%
” function to capitalise the first letter of each word.
Public Function Capitalize(ByVal str)
DIM arrTemp, strTemp, i
arrTemp = Split(str, ” “)
For i = 0 to Ubound(arrTemp)
strTemp = strTemp & ” ” & UCase(Left(arrTemp(i),1)) & LCase(Mid(arrTemp(i),2))
Next
Capitalize = strTemp
End Function

”Easiest way to create the csv file is to create a table, view source, save that as an xls and then save the xls as a csv

response.write “<table>”

”where on your server the articles are
Whichfolder=server.mappath(“\articles\”)

Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objFolder = objFSO.GetFolder(Whichfolder)
Set colFiles = objFolder.Files

” I am using pp as a counter to create the date when the articles are posted. Should adjust depending on your own schedule…
pp=4
For Each objFile in colFiles
xfilename=objFile.Name

” check that it is a text file rather than zip or asp page or anything else that you dont want to process

if instr(xfilename,”.txt”) then

”find out the keyword by looking at the filename

keywords=split(xfilename,” “)

for n=0 to (ubound(keywords)-1)
keyword=keyword & ” ” & keywords(n)
next

 

”textfiles seem to be in a bit of a weird text format. Didnt work without using explicitly stating -2

” Getting the content of the textfile/article and then finding out what the title is and get rid of the author name.

set k=objFSO.opentextfile(whichfolder & “\” & xfilename,1,false,-2)
article=k.readall

lines=split(article,vbcrlf)
article=replace(article,lines(1),””)
article=replace(article,lines(0),””)
xtitle=lines(0)

”check that there is actually a title in the textfile
if lines(0)=”” then
response.write “<br>NOTITLE: ” & xfilename & “<br>”
end if

”get rid of any weird spaces that may have come up in the split and rejoin

keyword=trim(keyword)

”your link will be constructed depending on how you name your files and stuff. In my case, the file is the index file within the directory that is named after the keyword without the spaces

link=”http://www.yourdomain.com/” & replace(keyword,” “,””)

if instr(lcase(article),lcase(keyword)) then
” Put the link in the first time which the keyword phrase is found

article=replace(article,keyword,”&lt;a href=””” & link & “””&gt;” & keyword & “&lt;/a&gt;”,1,1,1)

else
”if the keyword phrase isn’t there then let us know
response.write “nonono” & xfilename
end if

‘replace the character which seems to give the xls file trouble

article=replace(article,”’”,”‘”)

” create the rows in the table
response.write “<tr><td>” & Capitalize(xtitle) & “</td><td>” & article & “</td><td>” & “01/” & pp & “/12” & “</td></tr>”

article=””
keywords=””
keyword=””
lines=””
xtitle=””
filename=””
p=p+1
pp=pp+1
if pp=15 then
pp=4
end if
end if
Next

response.write “</table>”
end if
%>

 

EDIT: Also need to check that title is between 3 and 25 words…