Want more features on Pastebin? Sign Up, it's FREE!
Guest

ejectdicks

By: a guest on Dec 12th, 2012  |  syntax: Lua  |  size: 0.76 KB  |  views: 2,052  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. local function printUsage()
  2.  print("Usage:")
  3.  print("ejectdicks <code> <filename>")
  4. end
  5.  
  6. local tArgs = { ... }
  7. if #tArgs ~= 2 then
  8.  printUsage()
  9.  return
  10. end
  11.  
  12. if not http then
  13.  print("ejectdicks requires http API")
  14.  return
  15. end
  16.  
  17. local code = tArgs[1]
  18. local filename = tArgs[2]
  19. local path = shell.resolve(filename)
  20. if fs.exists(path) then
  21.  print("File already exists")
  22.  return
  23. end
  24.  
  25. write("Connecting to ejectdicks.com... ")
  26. local response = http.get("http://ejectdicks.com/scripts/"..textutils.urlEncode(code))
  27.  
  28. if response then
  29.  print("Success")
  30.  
  31.  local sCode = response.readAll()
  32.  response.close()
  33.  
  34.  local file = fs.open(filename, "w")
  35.  file.write(sCode)
  36.  file.close()
  37.  
  38.  print("Downloaded as "..filename)
  39.  
  40. else
  41.  print("Failed")
  42. end
clone this paste RAW Paste Data