Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- getany for ComputerCraft
- -- © 2017 zekro Development
- -- Install tool on ComputerCraft OS with
- -- > pastebin get BMfsbF4j getany
- -- Get usage info with:
- -- > getany
- -- Download a RAW online text file:
- -- > getany <filename> <url>
- -- INFO: <filename> needs to be ONE SINGLE STRING without spaces!
- local args = table.pack(...)
- function tablenght(intable)
- local count = 0
- for i in pairs(intable) do
- count = count + 1
- end
- return count
- end
- if args[1] == "info" then
- print("\nINFO:\n")
- print("(c) Copyright zekro 2017")
- print("\ndev.zekro.de - github.zekro.de")
- do return end
- end
- if tablenght(args) < 2 then
- print("\nUSAGE:\n")
- print(" Use this to download online RAW text file:\n > getany <name_of_program> <url>\n")
- print(" Use this to get informatio about the tool:\n > getany info")
- do return end
- end
- function download()
- content = http.get(args[2]).readAll()
- if not content then
- error("[ERROR] Could not download from " + args[2] + ".")
- end
- f = fs.open(args[1], "w")
- f.write(content)
- f.close()
- print("\nSuccessfully saved code from \n'", args[2], "' \nunder the name \n'", args[1], "' \non this computer.")
- end
- -- MAIN
- if string.sub(args[2], 1, 4) == "http" then
- download()
- else
- print("\nPlease enter a valid URL to download or enter argument 'info' to get information about that program.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement