Advertisement
9551

stock checker by 9551Dev

Aug 17th, 2021 (edited)
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.23 KB | None | 0 0
  1. --default for the "oculus quest 2"-
  2. --------------CONFIG---------------
  3. local webURL = "https://www.oculus.com/quest-2/"
  4. local checker = "<type<:<button<,<product<:<quest-2-128<,<text<:<Notify Me<}},<children<:[{<type<:<OCPlutoButton<,<props<:{<data-testid<:<quest-2-128_notify-me<,<ariaLabel<" --< means "
  5. local checkDelay = 20
  6. local updateFile = 2
  7. -----------------------------------
  8. print("stock checker by 9551Dev\n")
  9. if ccemux then
  10.     if not peripheral.wrap("top") then ccemux.attach("top", "speaker") end
  11.     local s = peripheral.wrap("top")
  12. end
  13. local data, match, str, count = nil, nil, nil, 2
  14. if not fs.exists("./stock.history") then fs.open("./stock.history", "w").close() end
  15. local ends = function()
  16.     term.setBackgroundColor(colors.black)
  17.     term.setTextColor(colors.white)
  18.     term.clear()
  19.     term.setCursorPos(1, 1)
  20. end
  21. local updateWeb = function()
  22.     print("updating web")
  23.     web, err = http.get(webURL)
  24. end
  25. local updateData = function()
  26.     print("updating data")
  27.     data = web.readAll()
  28. end
  29. local updateStr = function()
  30.     print("filtering STR")
  31.     str = data:gsub('"', "<")
  32. end
  33. local updateMatch = function()
  34.     print("matching")
  35.     match = str:find(checker, 1, true)
  36. end
  37. local errs = function(...)
  38.     web.close()
  39.     print(...)
  40. end
  41. local avaible = function()
  42.     local lives = true
  43.     local stop = function()
  44.         os.pullEvent("key")
  45.         lives = false
  46.     end
  47.     local blink = function()
  48.         while lives do
  49.             term.setBackgroundColor(colors.red)
  50.             term.clear()
  51.             sleep(.2)
  52.             term.setBackgroundColor(colors.green)
  53.             term.clear()
  54.             sleep(.2)
  55.         end
  56.     end
  57.     local sound = function()
  58.         if ccemux then
  59.             while lives do
  60.                 s.playNote("bell", 3, 24)
  61.                 sleep(.05)
  62.             end
  63.         end
  64.     end
  65.     parallel.waitForAll(stop, sound, blink)
  66. end
  67. local updateTime = function()
  68.     count = count + 1
  69.     if count >= updateFile then
  70.         print("updating stock.history file")
  71.         local av = false
  72.         if not match then av = true end
  73.         local of = fs.open("./stock.history", "r")
  74.         local od = of.readAll()
  75.         of.close()
  76.         local file = fs.open("./stock.history", "w")
  77.         local strs = (od or "") .. "\n" .. os.date() .. " avaibility: " .. tostring(av)
  78.         file.write(strs)
  79.         file.close()
  80.         count = 0
  81.     end
  82. end
  83. local main = function()
  84.     while true do
  85.         updateWeb()
  86.         if web then
  87.             updateData()
  88.             updateStr()
  89.             updateMatch()
  90.             updateTime()
  91.             if not match then
  92.                 print("item detected !!")
  93.                 sleep(2)
  94.                 avaible()
  95.                 break
  96.             end
  97.             print("done. nothing found\nstarting over in " .. tostring(checkDelay) .. " seconds..\n")
  98.             local posX, posY = term.getCursorPos()
  99.             print(("\173"):rep(checkDelay))
  100.             for i = 1, checkDelay do
  101.                 term.setCursorPos(1, posY)
  102.                 term.write(("\140"):rep(i))
  103.                 sleep(1)
  104.             end
  105.             print()
  106.         else
  107.             print("Web error... trying again")
  108.         end
  109.     end
  110. end
  111.  
  112. local ok, err = pcall(main)
  113. if not ok then
  114.     errs()
  115.     ends()
  116.     error(err, 0)
  117. end
  118. ends()
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement