Skip to content

Instantly share code, notes, and snippets.

@seriallos
Created February 5, 2013 03:42
Show Gist options
  • Save seriallos/4711976 to your computer and use it in GitHub Desktop.
Save seriallos/4711976 to your computer and use it in GitHub Desktop.
ComputerCraft program to download gists as programs. Yo dawg.
local tArgs = { ... }
if (#tArgs ~= 3) then
print( "USAGE: gist get GIST_ID PROGRAM_NAME" )
return
end
local action = tArgs[1]
local gist_id = tArgs[2]
local program = tArgs[3]
if "get" ~= action then
print( "Only 'get' is supported right now" )
return
end
if fs.exists( program ) then
print( "File "..program.." already exists. No action taken" )
return
end
-- TODO: maybe handle multifile gists?
local gist_url = "https://gist.github.com/raw/" .. gist_id
local request = http.get( gist_url )
local response = request.readAll()
request.close()
local file = fs.open( program, "w" )
file.write( response )
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment