Microsoft Small Basic

Program Listing:
Embed this in your website
' Blog Article List 0.6
' Copyright © 2014-2016 Nonki Takahashi. The MIT License.
' Last update 2016-03-19
' Program ID CPP576-1
'
TextWindow.Title = "Blog Article List 0.6"
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)
WQ = Text.GetCharacter(34)
SQ = "'"
Not = "False=True;True=False;"
site = "https://blogs.msdn.microsoft.com"
outfile = Program.Directory + "\BlogArticleList.html"
folder = "/smallbasic/"
nPosts = 0
maxPage = 1
outbuf = ""
block = ""
html = "" + CRLF
html = html + + WQ + ">" + CRLF
html = html + "" + CRLF
html = html + " + WQ + ">" + 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
html = html + "+ CRLF
For page = 1 To maxPage
  If page = 1 Then
    pg = ""
  Else
    pg = "page/" + page + "/"
  EndIf
  url = site + folder + pg + "?orderby=date"
  buf = Network.GetWebPageContents(url)
  p = 1
  eod = "False"
  While Not[eod]
    param = "tag=a;rel=bookmark;"
    FindTag()
    If tag = "" Then
      eod = "True"
    Else
      GetAttrAndText()
      ConvertText()
      block = block + "url | " + attr["href"] + CRLF
      block = block + "title | " + txt + CRLF
      html = html + "+ CRLF
      html = html + "+ CRLF
      param = "tag=time;class=entry-date published updated;"
      FindTag()
      html = html + "+ CRLF
      param = "tag=a;class=url fn n profile-usercard-hover;"
      FindTag()
      html = html + "+ CRLF
      html = html + "+ CRLF
      nArticle = nArticle + 1
      If Math.Remainder(nArticle, 3) = 0 Then
        TextWindow.Write(block + CRLF + nArticle + " articles" + CRLF + CRLF)
        outbuf = outbuf + block
        block = ""
        Program.Delay(700)
      EndIf
    EndIf
    block = block + CRLF
  EndWhile
  If page = 1 Then
    param = "tag=a;class=page-numbers;"
    FindTag()
    While tag <> ""
      tagSave = tag
      FindTag()
    EndWhile
    tag = tagSave
    GetAttrAndText()
    maxPage = txt
  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 + "
TITLE DATE POSTED BY
"
      html = html + "] + WQ + ">" + txt + ""
      html = html + "
"
      If tag = "" Then
        html = html + " "
        eod = "True"
      Else
        GetAttrAndText()
        block = block + "date | " + txt + CRLF
        html = html + txt
      EndIf
      html = html + "
"
      If tag = "" Then
        html = html + " "
        eod = "True"
      Else
        GetAttrAndText()
        block = block + "url | " + attr["href"] + CRLF
        block = block + "name | " + txt + CRLF
        html = html + "] + WQ + ">" + txt + ""
      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["rel"] - rel 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
      pTag = p + pTag - 1
      len = Text.GetIndexOf(Text.GetSubTextToEnd(buf, pTag), "/" + param["tag"] + ">")
      If 0 < len Then
        findNext = "True"     ' tag may be different
        lTag = Text.GetLength(param["tag"]) + 1
        len = len + lTag
        tag = Text.GetSubText(buf, pTag, len)
        Stack.PushValue("local", pTag)
        GetAttrAndText()
        pTag = Stack.PopValue("local")
        If param["class"] <> "" Then
          target = "class"
        Else
          target = "rel"
        EndIf
        If param[target] = attr[target] Then
          findNext = "False"  ' found the tag
        Else
          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
      pQ = Text.GetIndexOf(SQ + WQ, Text.GetSubText(tag, pEq + 1, 1))
      If 0 < pQ Then
        Q = Text.GetSubText(SQ + WQ, pQ, 1)
        pQ = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pEq + 2), Q)
        If 0 < pQ Then
          pQ = pEq + 2 + pQ - 1
          txt = Text.GetSubText(tag, pEq + 2, pQ - pEq - 2)
          ConvertText()
          attr[Text.GetSubText(tag, pTag, pEq - pTag)] = txt
          pTag = pQ + 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
Copyright (c) Microsoft Corporation. All rights reserved.