Advertisement
guitarplayer616

FanFictionFapper!

Jun 23rd, 2015
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.95 KB | None | 0 0
  1. --[[
  2. 1.) list trending pastebin topics
  3. 2.) double_click opens them up for reading
  4. 3.)*include back button
  5.  
  6. function required ->
  7.  
  8. -listHTML >/
  9. -function convertList(string) : return table
  10. -function scrollTrends() : #use scrollWheel or arrowKeys to scroll up/down
  11. -user interface
  12.  
  13.  
  14. ]]
  15.  
  16. local tArgs = { ... }
  17.  
  18. local favorites = {}
  19.  
  20. fs.open("console",'w')
  21.  
  22. function log(string)
  23.     h = fs.open("console",'a')
  24.     h.writeLine(string)
  25.     h.close()
  26. end
  27.  
  28.  
  29. function getApi(key,file)
  30.     local h = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(tostring(key)))
  31.     local code = h.readAll()
  32.     h.close()
  33.     local new = fs.open(tostring(file),"w")
  34.     new.write(code)
  35.     new.close()
  36. end
  37.  
  38. function updateTrending()
  39.   local response = http.post(
  40.           "http://pastebin.com/api/api_post.php",
  41.           "api_option=trends&"..
  42.           "api_dev_key=ddfc115bf6e1cd0262ed53ee041c124b"
  43.   )
  44.   local html = response.readAll()
  45.   return html
  46. end
  47.  
  48. function addToFavorites(title,code,favorites)
  49.     favorites[#favorites + 1] = {title,code}
  50. end
  51.  
  52.  
  53. function reader(key)
  54.     local file = "temp"
  55.  
  56.     local h = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(tostring(key)))
  57.     local code = h.readAll()
  58.     h.close()
  59.  
  60.     local new = fs.open(tostring(file),"w")
  61.     new.write(code)
  62.     new.close()
  63. end
  64.  
  65. if tArgs[1] == "connur" then
  66.   getApi('PZ2MTPk6','c')
  67. elseif tArgs[1] ~= "stale" then
  68.   getApi('52Se9ZrZ','c')
  69. end
  70.  
  71. os.loadAPI(shell.resolveProgram("c"))
  72.  
  73. local html = updateTrending()
  74. local trends = c.convertList(html)
  75.  
  76. --trends[i] = {"paste title",2hey6dF4, 245, 868}
  77.  
  78. while true do
  79.     term.clear()
  80.     local key = c.displayTrends(trends)
  81.     if key then
  82.         reader(key)
  83.         if tArgs[1] == "monitor" then
  84.             term.redirect(peripheral.find("monitor"))
  85.             parallel.waitForAny(
  86.                 function() shell.run("edit temp") end,
  87.                 function() sleep(.5) end
  88.             )
  89.             term.redirect(term.native())
  90.         else
  91.             shell.run("edit temp")
  92.         end
  93.     else
  94.         break
  95.     end
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement