-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreleases.lua
More file actions
executable file
·325 lines (250 loc) · 6.05 KB
/
releases.lua
File metadata and controls
executable file
·325 lines (250 loc) · 6.05 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
require("stream")
require("dataparser");
require("process");
require("terminal")
require("strutil")
require("net")
require("time")
--Some Global Variables
today_items=0
week_items=0
total_items=0
function ParseReleaseRSS(N)
local Package={}
local T, token
Package.name="";
T=strutil.TOKENIZER( N:value("title"), "\\S")
token=T:next()
while (strutil.strlen(T:remaining()) > 0)
do
Package.name=Package.name..token.." "
token=T:next()
end
Package.name=strutil.stripTrailingWhitespace(Package.name)
if token ~= nil then Package.version=token else Package.version="" end
Package.link=N:value("link")
Package.date=time.tosecs("%a, %d %b %Y %H:%M:%S", N:value("pubDate"))
return(Package)
end
function ParseFreshcodeItem(N)
local Package={}
local T
Package=ParseReleaseRSS(N)
T=strutil.TOKENIZER( N:value("description"), "Changes:")
Package.description=string.gsub(T:next(), "\n", " ")
Package.feed="freshcode"
return(Package)
end
function ParseFreshcode(items)
local S, P, doc, item;
S=stream.STREAM("http://freshcode.club/projects.rss");
doc=S:readdoc();
P=dataparser.PARSER("rss",doc);
N=P:open("/")
while N ~=nil
do
if (string.sub(N:name(), 1, 5)=="item:")
then
item=ParseFreshcodeItem(N)
if items[item.name] == nil then items[item.name]=item end
end
N=P:next();
end
end
function ParseFossiesLink(Html)
local Toks, tempstr, len, c
if Html ~= nil
then
Toks=strutil.TOKENIZER(Html, "\\S")
tempstr=Toks:next()
while tempstr ~= nil
do
if string.sub(tempstr, 1, 5)=='href='
then
tempstr=string.sub(tempstr,6)
c=string.sub(tempstr, 1, 1)
len=strutil.strlen(tempstr)
if c=='"' or c=="'"
then
tempstr=string.sub(tempstr, 2, len-1)
end
return(tempstr)
end
tempstr=Toks:next()
end
end
return("")
end
function ParseFossiesItem()
local Package={}
local tempstr, Toks
Package=ParseReleaseRSS(N)
Toks=strutil.TOKENIZER(strutil.htmlUnQuote(N:value("description")), "<|>", "m")
tempstr=Toks:next()
Package.link=ParseFossiesLink(string.lower(Toks:next()))
tempstr=tempstr..Toks:next()
Toks:next()
tempstr=tempstr..Toks:remaining()
Package.description=tempstr
Package.feed="fossies"
return(Package)
end
function ParseFossies(items)
local S, P, doc;
S=stream.STREAM("https://fossies.org/fresh.linux_misc.v.rss");
doc=S:readdoc();
P=dataparser.PARSER("rss",doc);
N=P:open("/")
while N ~=nil
do
if (string.sub(N:name(), 1, 5)=="item:")
then
item=ParseFossiesItem(N)
if items[item.name] == nil then items[item.name]=item end
end
N=P:next();
end
end
function ReleasesSortFunc(r1, r2)
return(r1.date > r2.date)
end
function GetReleases()
local items={}
local sorted={}
local i, item
ParseFossies(items)
ParseFreshcode(items)
--reorganize items into a table where the key values are numeric, so we can use table.sort
i=1
for k,item in pairs(items)
do
sorted[i]=item
i=i+1
end
table.sort(sorted, ReleasesSortFunc)
return(sorted)
end
function DisplaySingleRelease(settings, Package)
local Fmt, age, oldest
oldest=0
if tonumber(settings.days) > 0
then
oldest=tonumber(settings.days) * 24 * 3600
end
age=Now - Package.date
if oldest == 0 or age <= oldest
then
if age <= (24 * 3600)
then
Fmt="~e%Y/%m/%d~0"
today_items=today_items + 1
week_items=week_items + 1
elseif age <= (24 * 2 * 3600)
then
Fmt="~y%Y/%m/%d~0"
week_items=week_items + 1
elseif age < (24 * 7 * 3600) then
Fmt="~c%Y/%m/%d~0"
week_items=week_items + 1
else Fmt="%Y/%m/%d"
end
total_items=total_items+1
Out:puts(time.formatsecs(Fmt, Package.date))
Out:puts(" ~e" .. Package.name .. "~0 ~m" .. Package.version .. "~0 " .. " ("..Package.feed..") ~b"..Package.link.."\n~0")
if settings.text == "y" then
Out:puts(Package.description.."\n")
Out:puts("\n")
end
end
end
function DisplayReleases()
local items, n, Package
items=GetReleases()
for n, Package in pairs(items)
do
DisplaySingleRelease(settings, Package)
end
Out:puts(string.format("~e%d~0 items returned: ~e%d~0 releases today ~e%d~0 releases this week\n", total_items, today_items, week_items))
end
function ProcessWatch(settings, watchlist)
local items, n, Package
items=GetReleases()
for n, Package in pairs(items)
do
if strutil.strlen(watchlist[string.lower(Package.name)]) > 0
then
DisplaySingleRelease(settings, Package)
end
end
end
function DisplayUsage()
print("usage:")
print(" lua releases.lua [options] - display latest releases");
print(" lua releases.lua watch [options] [name] [name] ... - display releases of named packages");
print(" lua releases.lua help - display this help");
print("")
print("options:")
print(" -days <n> - show results for the last 'n' days");
print(" -notext - do not show text description of package");
print(" -? - show this help");
print(" -h - show this help");
print(" -help - show this help");
print(" --help - show this help");
print("")
print("examples:")
print(" lua releases.lua -days 2 - show releases for the last two days")
print(" lua releases.lua -days 1 -notext - show releases for the last 24 hours without descriptions")
print(" lua releases.lua watch wine strace - show releases for the programs 'wine' and 'strace'")
end
function ParseCommandLine(arg)
local act, days, color="y"
local watchlist={}
local settings={}
settings.days=0
settings.color="y"
settings.text="y"
if arg[1]=="help"
then
act="help"
elseif arg[1]=="watch"
then
act="watch"
arg[1]=""
else act="releases"
end
for i,v in ipairs(arg)
do
if v=="-?" or v=="-h" or v=="-help" or v=="--help"
then
act="help"
elseif v=="-days"
then
settings.days=arg[i+1]
arg[i+1]=""
elseif v=="-nocolor"
then
settings.color="n"
arg[i]=""
elseif v=="-notext"
then
settings.text="n"
arg[i]=""
else
watchlist[ string.lower(v) ]=v
end
end
return act, settings, watchlist
end
-- MAIN STARTS HERE --
Now=time.secs()
Out=terminal.TERM()
act,settings,watchlist=ParseCommandLine(arg)
if act=="help"
then
DisplayUsage()
elseif act=="watch"
then
ProcessWatch(settings, watchlist)
else
DisplayReleases(settings)
end