Advertisement
Guest User

ejectdicks

a guest
Dec 12th, 2012
2,520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.76 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement