Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w, h = term.getSize()
- local oTemp = fs.open("console", "w")
- function log(string)
- oTemp.writeLine(string)
- oTemp.flush()
- end
- function beginWrite(str)
- local str = str or ""
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- write(str)
- end
- function getPastes(html)
- local pastes = {}
- while #html > 0 do
- local _, st = html:find("<paste_key>")
- local en = html:find("</paste_key>")
- pastes[#pastes + 1] = html:sub(st + 1, en - 1)
- _, en = html:find("</paste>")
- html = html:sub(en + 1)
- end
- return pastes
- end
- function drawProgressBar(remaining, total)
- term.setBackgroundColor(colors.lightBlue)
- term.setCursorPos(1, h)
- write(string.rep(" ", ((total - remaining) / total) * w))
- end
- function getNum(pastes)
- local num = 0
- local len = #pastes
- local count = 1
- while #pastes > 0 do
- local current = table.remove(pastes)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1, count < h and count or h)
- write("Connecting to " .. current .. "...")
- print(string.rep(" ", w - 25))
- drawProgressBar(#pastes, len)
- local response = http.get(
- "http://pastebin.com/raw.php?i=" .. textutils.urlEncode(current)
- )
- local response = response.readAll()
- local newLine = 0
- for i in string.gmatch(response, "\n") do
- newLine = newLine + 1
- end
- num = num + newLine + 1
- count = count + 1
- end
- return num
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.blue)
- print("Pastebin CodeCounter")
- term.setTextColor(colors.cyan)
- write("Enter Username: ")
- term.setTextColor(colors.white)
- local username = read()
- term.setCursorPos(1, 3)
- term.setTextColor(colors.cyan)
- write("Enter Password :) : ")
- term.setTextColor(colors.white)
- local password = read("*")
- term.setCursorPos(1, 4)
- term.setTextColor(colors.cyan)
- write("Paste dev key here: ")
- term.setTextColor(colors.yellow)
- local devkey = read()
- beginWrite("Logging in...")
- local postdata = http.post(
- "http://pastebin.com/api/api_login.php",
- "api_option=login&"..
- "api_dev_key="..devkey.."&"..
- "api_user_name="..textutils.urlEncode(username).."&"..
- "api_user_password="..textutils.urlEncode(password)
- )
- local userkey = postdata.readAll()
- if #userkey ~= 32 then
- error("Invalid login")
- end
- beginWrite("Retrieving paste list...")
- local list = http.post("http://pastebin.com/api/api_post.php",
- "api_dev_key=" .. devkey ..
- "&api_user_key=" .. userkey ..
- "&api_results_limit=1000" ..
- "&api_option=list")
- list = list.readAll()
- beginWrite()
- local pastes = getPastes(list)
- local num = getNum(pastes)
- log(num)
- log("=====")
- log(list)
- beginWrite()
- write("You have written approximately ")
- term.setTextColor(colors.lightBlue)
- write(tostring(num))
- term.setTextColor(colors.white)
- write(" lines of code so far!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement