Microsoft Small Basic

Program Listing: CPP576-0
' Blog Article List 0.5
' Copyright © 2014-2015 Nonki Takahashi. The MIT License.
' Last update 2015-10-10
' Program ID CPP576-0
'
TextWindow.Title = "Blog Article List 0.5"
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)
WQ = Text.GetCharacter(34)
Not = "False=True;True=False;"
site = "http://blogs.msdn.com"
outfile = Program.Directory + "\BlogArticleList.html"
folder = "/b/smallbasic/default.aspx?PageIndex="
nPosts = 0
maxPage = 1
outbuf = ""
block = ""
html = "" + CRLF
html = html + "" + CRLF
html = html + "" + CRLF
html = html + "" + CRLF
html = html + "Small Basic - The Official Blog of Small Basic" + CRLF
html = html + "" + CRLF
html = html + "" + CRLF
html = html + "

Small Basic - The Official Blog of Small Basic

" + CRLF
html = html + "" + CRLF
html = html + "" + CRLF
html = html + "" + CRLF
html = html + "" + CRLF
html = html + "" + CRLF
For page = 1 To maxPage
buf = Network.GetWebPageContents(site + folder + page)
p = 1
eod = "False"
While Not[eod]
param = "tag=a;class=internal-link view-post;"
FindTag()
If tag = "" Then
eod = "True"
Else
GetAttrAndText()
ConvertText()
block = block + "url | " + site + attr["href"] + CRLF
block = block + "title | " + txt + CRLF
html = html + "" + CRLF
html = html + "" + CRLF
param = "tag=a;class=internal-link view-user-profile;"
FindTag()
html = html + "" + CRLF
html = html + "" + CRLF
nArticle = nArticle + 1
If Math.Remainder(nArticle, 4) = 0 Then
TextWindow.Write(block + CRLF + nArticle + " articles")
outbuf = outbuf + block
block = ""
Program.Delay(700)
EndIf
EndIf
block = block + CRLF
EndWhile
If page = 1 Then
param = "tag=a;class=last;"
FindTag()
GetAttrAndText()
maxPage = Text.GetSubTextToEnd(attr["href"], Text.GetIndexOf(attr["href"], "=") + 1)
EndIf
EndFor
block = block + CRLF + nArticle + " articles" + CRLF
If Math.Remainder(nArticle, 4) = 0 Then
TextWindow.WriteLine(CRLF)
Else
TextWindow.WriteLine(block)
EndIf
outbuf = outbuf + block
html = html + "
TITLEPOSTED BY
"
html = html + "" + txt + ""
html = html + "
"
If tag = "" Then
html = html + " "
eod = "True"
Else
GetAttrAndText()
block = block + "url | " + site + attr["href"] + CRLF
block = block + "name | " + txt + CRLF
html = html + "" + txt + "" + CRLF
EndIf
html = html + "
" + CRLF
html = html + "

Total " + nArticle + " articles.

" + CRLF
html = html + "" + CRLF
' The following line could be harmful and has been automatically commented.
' File.WriteContents(outfile, html) ' outbuf for text
Sub ConvertText
' convert &*; to unicode character
' param txt
' return txt
While Text.IsSubText(txt, "&")
c = Text.GetIndexOf(txt, "&")
l = Text.GetIndexOf(Text.GetSubTextToEnd(txt, c), ";")
kw = Text.GetSubText(txt, c + 1, l - 2)
If Text.StartsWith(kw, "#") Then
txtMid = Text.GetCharacter(Text.GetSubTextToEnd(kw, 2))
ElseIf kw = "quot" Then
txtMid = Text.GetCharacter(34)
Else
txtMid = ""
EndIf
txtLeft = Text.GetSubText(txt, 1, c - 1)
txtRight = Text.GetSubTextToEnd(txt, c + l)
txt = Text.Append(txtLeft, Text.Append(txtMid, txtRight))
EndWhile
EndSub
Sub FindTag
' find tag from html buffer
' param["tag"] - tag name
' param["class"] - class name
' param p - pointer for buffer
' param buf - html buffer
' return tag - found tag
pSave = p
tag = ""
findNext = "True"
While findNext
findNext = "False" ' tag may be not found
pTag = Text.GetIndexOf(Text.GetSubTextToEnd(buf, p), "<" + param["tag"])
If 0 < pTag Then
lTag = Text.GetLength(param["tag"]) + 1
pTag = p + pTag - 1
len = Text.GetIndexOf(Text.GetSubTextToEnd(buf, pTag), "/" + param["tag"] + ">")
If 0 < len Then
findNext = "True" ' tag may have different class
len = len + lTag
attr = "class=" + WQ + param["class"] + WQ
pAttr = pTag + lTag + 1
lAttr = Text.GetLength(attr)
If Text.GetSubText(buf, pAttr, lAttr) = attr Then
tag = Text.GetSubText(buf, pTag, len)
findNext = "False" ' found the tag
EndIf
p = pTag + len
EndIf
EndIf
EndWhile
If tag = "" Then
p = pSave
EndIf
EndSub
Sub GetAttrAndText
' get attributes and text from given tag
' param tag - given tag
' return attr[] - array of attributes in the tag
' return txt - text in the tag
pTag = Text.GetIndexOf(tag, " ") + 1
pEnd = Text.GetIndexOf(tag, ">")
attr = ""
While pTag <= pEnd
pEq = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pTag), "=")
If 0 < pEq Then
pEq = pTag + pEq - 1
If Text.GetSubText(tag, pEq + 1, 1) = WQ Then
pWQ = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pEq + 2), WQ)
If 0 < pWQ Then
pWQ = pEq + 2 + pWQ - 1
attr[Text.GetSubText(tag, pTag, pEq - pTag)] = Text.GetSubText(tag, pEq + 2, pWQ - pEq - 2)
pTag = pWQ + 2
EndIf
EndIf
Else
pTag = pEnd + 1
EndIf
EndWhile
len = Text.GetLength(tag)
txt = ""
While pTag <= len
pL = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pTag), "<")
If pL = 0 Then
txt = Text.Append(txt, Text.GetSubTextToEnd(tag, pTag))
pTag = len + 1
Else
pL = pTag + pL - 1
txt = Text.Append(txt, Text.GetSubText(tag, pTag, pL - pTag))
pR = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pTag), ">")
If 0 < pR Then
pTag = pTag + pR
Else
pTag = len + 1
EndIf
EndIf
EndWhile
EndSub