-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtcclient.lua
More file actions
50 lines (43 loc) · 1.59 KB
/
tcclient.lua
File metadata and controls
50 lines (43 loc) · 1.59 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
local args = {...}
local function printArgs()
print("The Timely Krist download client")
print("Usage:")
print("tcclient list")
print(" - List all published issues")
print("tcclient get <issue> <fn>")
print(" - Save <issue> to <fn> as a 2dj file")
print("tcclient print <issue>")
print(" - Print <issue> directly")
end
if #args < 1 then
printArgs()
return
end
if args[1] == "list" then
local response = http.get("https://raw.githubusercontent.com/scmcgowen/the-timely-krist/main/issue_list.txt")
term.clear()
term.setCursorPos(1,1)
print("Current issues:")
textutils.pagedPrint(response.readAll())
response.close()
elseif args[1] == "get" and args[2] and args[3] then
print("Downloaded issue "..args[2])
local response = http.get("https://raw.githubusercontent.com/scmcgowen/the-timely-krist/main/issues/issue_"..args[2]..".2dj",nil,true)
local f = assert(fs.open(args[3], "wb"))
f.write(response.readAll())
response.close()
f.close()
print("Downloaded issue "..args[2])
elseif args[1] == "print" and args[2] then
shell.run("poster https://raw.githubusercontent.com/scmcgowen/the-timely-krist/main/issues/issue_"..args[2]..".2dj")
elseif args[1] == "update" then
print("Updating Client")
local response = http.get("https://raw.githubusercontent.com/scmcgowen/the-timely-krist/main/issues/issue_"..args[2]..".2dj",nil,true)
local f = assert(fs.open(shell.getRunningProgram, "wb"))
f.write(response.readAll())
response.close()
f.close()
print("Successfully updated.")
else
printArgs()
end