Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local wraptext = require "cc.strings".wrap
- local function tb_str(pr,str)
- for id,i in ipairs(str) do
- pr.write(i)
- pr.setCursorPos(1,select(2,pr.getCursorPos())+1)
- end
- end
- local news = http.get("https://newsapi.org/v2/top-headlines?pageSize=5&language=en&category=science&apiKey=fc35c45cab1744e18aa6eda1c805971a").readAll()
- local json = textutils.unserialiseJSON(news)
- local pr = peripheral.wrap("bottom")
- if not pr.newPage() then
- print("Could not start printing")
- return 1
- end
- local w,h = pr.getPageSize()
- pr.setPageTitle("Newspaper")
- if json.status == "ok" then
- for id,i in ipairs(json.articles) do
- tb_str(pr,wraptext(id..". "..i.title.."\n",w))
- end
- end
- pr.endPage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement