Advertisement
AdditionalPylons

Newspaper

Mar 21st, 2025
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.72 KB | None | 0 0
  1. local wraptext = require "cc.strings".wrap
  2. local function tb_str(pr,str)
  3.     for id,i in ipairs(str) do
  4.         pr.write(i)
  5.         pr.setCursorPos(1,select(2,pr.getCursorPos())+1)
  6.     end
  7. end
  8. local news = http.get("https://newsapi.org/v2/top-headlines?pageSize=5&language=en&category=science&apiKey=fc35c45cab1744e18aa6eda1c805971a").readAll()
  9. local json = textutils.unserialiseJSON(news)
  10. local pr = peripheral.wrap("bottom")
  11. if not pr.newPage() then
  12.     print("Could not start printing")
  13.     return 1
  14. end
  15. local w,h = pr.getPageSize()
  16. pr.setPageTitle("Newspaper")
  17. if json.status == "ok" then
  18.     for id,i in ipairs(json.articles) do
  19.         tb_str(pr,wraptext(id..". "..i.title.."\n",w))
  20.     end
  21. end
  22. pr.endPage()
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement