Advertisement
fatboychummy

TriGet

Jan 21st, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.72 KB | None | 0 0
  1. --[[Description:
  2.   API for grabbing files from pages.
  3.   Like the pastebin program, but as an api (and grabs from any URL)
  4.   Github/Pastebin built-in
  5.   must be "require"'d, or "dofile"'d
  6. ]]
  7.  
  8.  
  9.  
  10. --Made by Fatboychummy, Do not redistribute, do not modify.
  11.  
  12. local api = {}
  13.  
  14. local get = function(url,file) --Get the file, returns if passed or failed.
  15.   local h = http.get(url) --Get the url
  16.   local er = "failed to open url"
  17.   if h then
  18.     local h2 = fs.open(file,"w") --Get the file
  19.     local er = "failed to open file"
  20.     if h2 then
  21.       h2.write(h.readAll()) --Write
  22.       h.close()
  23.       h2.close()
  24.       return true --Return passed
  25.     end
  26.   end
  27.   return false,er --If failed, return false and the corrosponding error.
  28. end
  29.  
  30.  
  31. api.GetPastebin = function(loc,file) --Get files from pastebin, using the shortened location (ie: ABCDEFGH)
  32.   local url = "https://pastebin.com/raw/" .. loc
  33.   return get(url,file) --Actually grab the file
  34. end
  35.  
  36. api.GetGithub = function(user,repo,branch,fileToGet,fileToWrite)
  37.   --[[
  38.     Grabs stuff from GitHub
  39.     Structure of input:
  40.  
  41.     {
  42.       user = "theUserName",
  43.       repo = "theRepoName",
  44.       branch = "theBranchName",
  45.       file = "theFileName",
  46.     }
  47.  
  48.     example: GetGithub("fatboychummy","InventoryMods","master","main.lua","startup.lua")
  49.  
  50.     To get a file from a folder, just do "foldername/filename" for 'fileToGet'
  51.  
  52.   ]]
  53.   local url = "https://raw.githubusercontent.com/" .. user .. "/" .. repo .. "/" .. branch .. "/" .. fileToGet
  54.   return get(url,fileToWrite)
  55. end
  56.  
  57. api.Grab = function(url,file) --Get a file directly, using direct url
  58.   return get(url,file) --Because api.grab cannot see api.get, apparantly.  Thank you Kanye, very cool.
  59. end
  60.  
  61. return api
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement