-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGoogleBlogArticleList.sb
More file actions
175 lines (173 loc) · 4.92 KB
/
GoogleBlogArticleList.sb
File metadata and controls
175 lines (173 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
' Google Blog Article List 0.6
' Copyright © 2014-2025 Nonki Takahashi. The MIT License.
' Last update 2025-06-21
' Program ID PLT187-2
'
TextWindow.Title = "Google Blog Article List 0.6"
Not = "False=True;True=False;"
LT = "<"
site = "https://nonkit.blogspot.jp/"
eob = "False" ' end of blog
first = "True"
classH3 = "tag=h3;class=post-title;"
nextH3 = "tag=h3;class=post-title entry-title;"
nArticle = 0
stdout = Program.Directory + "/list.html"
File.WriteContents(stdout, LT + "!DOCTYPE html>")
File.AppendContents(stdout, LT + "html lang='en'>")
File.AppendContents(stdout, LT + "head>")
File.AppendContents(stdout, LT + "meta charset='UTF-8'>")
File.AppendContents(stdout, LT + "title>Nonkit Blog - Table of Contents" + LT + "/title>")
File.AppendContents(stdout, LT + "/head>")
File.AppendContents(stdout, LT + "body>")
dateLast = ""
While Not[eob]
TextWindow.WriteLine(site)
buf = Network.GetWebPageContents(site)
pNotFound = Text.GetLength(buf) + 1
p = 1
eod = "False"
While Not[eod]
param = "tag=time;class=published;"
FindTag()
pTime = pNotFound
If tag <> "" Then
pTime = p
GetAttrAndText()
date = txt
If date <> dateLast Then
If dateLast <> "" Then
File.AppendContents(stdout, LT + "/ul>")
EndIf
File.AppendContents(stdout, LT + "p>" + date + LT + "/p>")
File.AppendContents(stdout, LT + "ul>")
dateLast = date
EndIf
EndIf
param = classH3
FindTag()
If first Then
first = "False"
classH3 = nextH3
EndIf
pH3 = pNotFound
If tag <> "" Then
pH3 = p
bufSave = buf
p = 1
buf = tag
param = "tag=a;"
FindTag()
GetAttrAndText()
href = attr["href"]
title = txt
buf = bufSave
p = pH3
param = "tag=time;"
FindTag()
GetAttrAndText()
File.AppendContents(stdout, LT + "li>" + LT + "a href='" + href + "'>" + title + LT + "/a>" + LT + "/li>")
nArticle = nArticle + 1
EndIf
If pTime = pNotFound And pH3 = pNotFound Then
eod = "True"
EndIf
EndWhile
param = "tag=a;class=blog-pager-older-link;"
FindTag()
If tag = "" Then
eob = "True"
Else
GetAttrAndText()
site = attr["href"]
EndIf
EndWhile
File.AppendContents(stdout, LT + "/ul>")
File.AppendContents(stdout, LT + "p>Total " + nArticle + " articles." + LT + "/p>")
File.AppendContents(stdout, LT + "/body>")
File.AppendContents(stdout, LT + "/html>")
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), LT + 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 param["class"] = "" Then
len = len + lTag
tag = Text.GetSubText(buf, pTag, len)
findNext = "False" ' found the tag
ElseIf 0 < len Then
findNext = "True" ' tag may have different class
len = len + lTag
attr = "class=" + "'" + param["class"] + "'"
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) = "'" Then
pQ = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pEq + 2), "'")
If 0 < pQ Then
pQ = pEq + 2 + pQ - 1
attr[Text.GetSubText(tag, pTag, pEq - pTag)] = Text.GetSubText(tag, pEq + 2, pQ - pEq - 2)
pTag = pQ + 2
EndIf
EndIf
Else
pTag = pEnd + 1
EndIf
EndWhile
If pEnd + 1 < pTag Then
pTag = pEnd + 1
EndIf
len = Text.GetLength(tag)
txt = ""
While pTag <= len
pL = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pTag), LT)
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