Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Program made by Warfar
- --http://pastebin.com/u/warfar
- local function printUsage()
- print( "Usages:" )
- print( "get <code> <filename>" )
- end
- local tArgs = { ... }
- if #tArgs ~= 2 then
- printUsage()
- return
- end
- if not http then
- print( "Pastebin requires http API" )
- print( "Set enableAPI_http to 1 in mod_ComputerCraft.cfg" )
- return
- end
- local sCode
- local l = #tArgs[1]
- if l == 28 then
- sCode = string.sub(tArgs[1], -8)
- elseif l == 8 then
- sCode = tArgs[1]
- else printUsage()
- return
- end
- for _,v in ipairs(redstone.getSides()) do
- if peripheral.getType(v) == "disk"
- diskFound = true
- break
- else
- diskFound = false
- end
- end
- if not diskFound then
- print("No disk drive found")
- end
- -- Determine file to download
- local sFile = tArgs[2]
- local sPath = shell.resolve( sFile )
- -- GET the contents from pastebin
- write( "Connecting" )
- local response = http.get(
- "http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode )
- )
- if response then
- term.clear()
- term.setCursorPos(1,1)
- print( "Success." )
- local sResponse = response.readAll()
- response.close()
- if fs.exists("disk/"..sPath) then
- write("Override? y/n")
- local choice = io.read()
- if choice == "y" then
- fs.delete("disk/"..sPath)
- else
- print("File Exists")
- return
- end
- end
- local file = fs.open("disk/"..sPath, "w" )
- file.write( sResponse )
- file.close()
- else
- print( "Failed." )
- end
Advertisement
Add Comment
Please, Sign In to add comment