Clem105

Put GIF on Pastebin

Apr 12th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.45 KB | None | 0 0
  1. local function printUsage() -- Program from ImGoodDisher , credits : http://pastebin.com/aZheqT4C
  2. print( "Usages:" )
  3. print( "pastebin put <filename>" )
  4. print( "pastebin get <code> <filename>" )
  5. end
  6. local tArgs = { ... }
  7. if #tArgs < 2 then
  8. printUsage()
  9. return
  10. end
  11. h = fs.open("Data","w")
  12. local sCommand = tArgs[1]
  13. if sCommand == "put" then
  14. -- Upload a file to pastebin.com
  15. -- Determine dir to upload
  16. local sFile = tArgs[2]
  17. if not fs.exists( sFile ) then
  18. print( "No such file or Dir" )
  19. return
  20. end
  21. t = fs.find(sFile.."/")
  22. for i =1,#t do
  23.     sName[i] = fs.getName(t[i])
  24.  
  25. -- Read in the file
  26.     local file[i] = fs.open( t[i], "r" )
  27.     local sText[i] = file.readAll()
  28.     file[i].close()
  29. end
  30. -- Log in
  31. print("Log in? y/n")
  32. while true do
  33.     login = read()
  34.     if login == "y" or login == "n" then
  35.         break
  36.     end
  37. end
  38. if login == "y" then
  39.     write("Username: ")
  40.     username = textutils.urlEncode(read())
  41.     write("Password: ")
  42.     password = textutils.urlEncode(read("*"))
  43. end
  44. write( "Connecting to pastebin.com... " )
  45. local key = "0ec2eb25b6166c0c27a394ae118ad829"
  46. for 1,#t do
  47.     if login == "y" then
  48.         local userraw = http.post(
  49.         "http://pastebin.com/api/api_login.php",
  50.         "api_dev_key="..key.."&"..
  51.         "api_user_name="..username.."&"..
  52.         "api_user_password="..password
  53.         )
  54.         -- get user code in annoying roundabout way
  55.         -- error/bug/?: userraw[1]() doesn't work
  56.         for i,v in pairs(userraw) do
  57.             user = v()
  58.             break
  59.         end
  60.         -- check for errors with pastebin
  61.         if string.sub(user, 1, 3) == "Bad" then print("\n"..user) error("") end
  62.         local response[i] = http.post(
  63.         "http://pastebin.com/api/api_post.php",
  64.         "api_option=paste&"..
  65.         "api_dev_key="..key.."&"..
  66.         "api_user_key="..user.."&"..
  67.         "api_paste_format=lua&"..
  68.         "api_paste_name="..textutils.urlEncode(sName[i]).."&"..
  69.         "api_paste_code="..textutils.urlEncode(sText[i])
  70.         )
  71.  
  72.         print("Done "..i)
  73.     else
  74.         local response[i] = http.post(
  75.         "http://pastebin.com/api/api_post.php",
  76.         "api_option=paste&"..
  77.         "api_dev_key="..key.."&"..
  78.         "api_paste_format=lua&"..
  79.         "api_paste_name="..textutils.urlEncode(sName[i]).."&"..
  80.         "api_paste_code="..textutils.urlEncode(sText[i])
  81.         )
  82.     end
  83.     if response then
  84.         print( "Success." )
  85.         local sResponse = response.readAll()
  86.         response.close()
  87.         local sCode = string.match( sResponse, "[^/]+$" )
  88.         print( "Uploaded as "..sResponse )
  89.         print( "Run \"pastebin get "..sCode.."\" to download anywhere" )
  90.         h.writeLine(sCode)
  91.     else
  92.         print( "Failed." )
  93.     end
  94. end
Add Comment
Please, Sign In to add comment