Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Loading API
- os.loadAPI("json")
- -- Change if your config is different
- local info = {
- monitor = "back",
- noteblock = "top",
- baseUrl = "YOUR LINK"
- }
- local research = { YOUR HTAG AND OTHER }
- local authorPack = { Change Color for name }
- local running = true
- local counter = 0
- local leftTweets = 0
- local sep = ""
- local mon = peripheral.wrap(info.monitor)
- local nb = peripheral.wrap(info.noteblock)
- local tweets = {}
- term.redirect(mon)
- local size = {term.getSize()}
- local mainWindow = window.create(term.current(), 1, 3, size[1], size[2] - 1, true)
- local function update(search)
- local url = info.baseUrl.."updateTweet.php?search="..search
- local resultHttp = http.get(url)
- local content = json.decode(resultHttp.readAll())
- resultHttp.close()
- return content
- end
- local function getTweet()
- local url = info.baseUrl.."getAndReadTweets.php"
- local resultHttp = http.get(url)
- local content = json.decode(resultHttp.readAll())
- resultHttp.close()
- return content
- end
- local function isTweetExist(id_search, tab)
- local counterNoStop = 0
- for k, v in pairs(tab) do
- counterNoStop = counterNoStop + 1
- if counterNoStop > 100 then
- counterNoStop = 0
- os.sleep(0.1)
- end
- if v.id_tweet == id_search then
- return true
- end
- end
- return false
- end
- local function isAuthorExist(authorSearch, tab)
- for k, v in pairs(tab) do
- if v == authorSearch then
- return true
- end
- end
- return false
- end
- local function updateBDD()
- while running do
- for k, v in pairs(research) do
- update(v)
- end
- os.sleep(20)
- end
- end
- local function updateTweets()
- while running do
- local result = getTweet()
- if result.nbTweetRead > 0 then
- counter = 0
- leftTweets = result.nbTweetLeft
- for k, v in pairs(result.data) do
- if not isTweetExist(v.id_tweet, tweets) then
- local contentModif = v.content
- contentModif = contentModif:gsub("u00e9","e")
- contentModif = contentModif:gsub("u00e7","c")
- contentModif = contentModif:gsub("u00e0","a")
- contentModif = contentModif:gsub("u00a0"," ")
- local tweet = {
- id_tweet = v.id_tweet,
- content = contentModif,
- author = v.author,
- search = v.search,
- created = v.created
- }
- table.insert(tweets, tweet)
- end
- end
- else
- counter = counter + 1
- if counter > 25 then
- counter = 20
- end
- end
- os.sleep(1)
- end
- end
- local function drawIHM()
- while running do
- term.redirect(mon)
- term.setCursorPos(1, 1)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clearLine()
- term.setCursorPos(1, 1)
- print(" Restant : ", #tweets, " # Non lu : ", leftTweets)
- term.redirect(mainWindow)
- local ts = tweets[1]
- if ts ~= nil then
- local sc = math.pow(2, math.random(2, 14))
- term.setTextColor(sc)
- term.setBackgroundColor(colors.black)
- if isAuthorExist(ts.author, authorPack) then
- term.setBackgroundColor(colors.white)
- end
- print(sep)
- if #tweets < 20 then os.sleep(0.1) end
- print(" "..ts.content)
- if #tweets < 40 then os.sleep(0.1) end
- print(" From : "..ts.author)
- if #tweets < 100 then os.sleep(0.1) end
- print(sep)
- if #tweets < 300 then os.sleep(0.1) end
- nb.playNote(0, math.random(1, 24))
- end
- table.remove(tweets, 1)
- os.sleep(0.1)
- end
- end
- local sx, sy = term.getSize()
- for i = 1, sx do
- sep = sep.."-"
- end
- term.clear()
- term.setCursorPos(1, 1)
- term.redirect(mainWindow)
- parallel.waitForAll(updateBDD, updateTweets, drawIHM)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement