Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[Description:
- API for grabbing files from pages.
- Like the pastebin program, but as an api (and grabs from any URL)
- Github/Pastebin built-in
- must be "require"'d, or "dofile"'d
- ]]
- --Made by Fatboychummy, Do not redistribute, do not modify.
- local api = {}
- local get = function(url,file) --Get the file, returns if passed or failed.
- local h = http.get(url) --Get the url
- local er = "failed to open url"
- if h then
- local h2 = fs.open(file,"w") --Get the file
- local er = "failed to open file"
- if h2 then
- h2.write(h.readAll()) --Write
- h.close()
- h2.close()
- return true --Return passed
- end
- end
- return false,er --If failed, return false and the corrosponding error.
- end
- api.GetPastebin = function(loc,file) --Get files from pastebin, using the shortened location (ie: ABCDEFGH)
- local url = "https://pastebin.com/raw/" .. loc
- return get(url,file) --Actually grab the file
- end
- api.GetGithub = function(user,repo,branch,fileToGet,fileToWrite)
- --[[
- Grabs stuff from GitHub
- Structure of input:
- {
- user = "theUserName",
- repo = "theRepoName",
- branch = "theBranchName",
- file = "theFileName",
- }
- example: GetGithub("fatboychummy","InventoryMods","master","main.lua","startup.lua")
- To get a file from a folder, just do "foldername/filename" for 'fileToGet'
- ]]
- local url = "https://raw.githubusercontent.com/" .. user .. "/" .. repo .. "/" .. branch .. "/" .. fileToGet
- return get(url,fileToWrite)
- end
- api.Grab = function(url,file) --Get a file directly, using direct url
- return get(url,file) --Because api.grab cannot see api.get, apparantly. Thank you Kanye, very cool.
- end
- return api
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement