Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local loc = "/advent/"
- local fileName = "Challenge"
- local dirName = "Day"
- local fileToGrab = "hdF9mauN" ---------------------------------------------------------
- local tArgs = {...}
- local day = tArgs[1]
- local challenge = tArgs[2]
- assert(type(tonumber(day)) == "number", "Bad input: #1, expected number.")
- assert(type(tonumber(challenge)) == "number", "Bad input: #2, expected number.")
- assert(tonumber(challenge) >= 1 and tonumber(challenge) <= 25 and tonumber(challenge) % 1 == 0,"Badinput: #2, expected number (1-25)")
- fileName = fileName .. challenge
- dirName = dirName .. day .. "/"
- if not fs.isDir(loc..dirName) then
- fs.makeDir(dirName)
- end
- fs.delete(loc .. dirName .. fileName)
- do
- print()
- print("Attempting to download file from Pastebin: "..fileToGrab)
- print("Connecting to Pastebin...")
- local h1 = http.get("https://pastebin.com/raw/"..fileToGrab)
- if h1 then
- print("Connected!")
- print("Opening file: ".. loc .. dirName .. fileName)
- local h2 = fs.open(loc .. dirName .. fileName,"w")
- if h2 then
- print("File successfully opened!")
- h2.write(h1.readAll())
- h2.writeLine()
- h2.close()
- print("Download success!")
- else
- error("Failed to open local file.")
- end
- h1.close()
- else
- error("Failed to connect to pastebin.")
- end
- end
Add Comment
Please, Sign In to add comment