Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("json")
- mon = peripheral.wrap("top")
- mon.clear()
- w, h = mon.getSize()
- -- Lade JSON Daten von der URL
- a = http.get("http://lyco-web.justin-wittwer.de/old_players")
- rawJson = a.readAll()
- parsedJson = json.json_decode(rawJson)
- -- Setze den Header Text
- mon.setCursorPos(1,1)
- mon.setTextColor(colors.orange)
- mon.write("Player whose plots get")
- mon.setCursorPos(1,2)
- mon.write("reset within the next 60 days")
- mon.setCursorPos(1,3)
- mon.write("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
- -- Konvertiere die JSON-Daten in eine Liste
- local playerList = {}
- for k, v in pairs(parsedJson) do
- table.insert(playerList, {name = k, value = tonumber(v)})
- end
- -- Sortiere die Liste nach den Werten in absteigender Reihenfolge
- table.sort(playerList, function(a, b)
- return a.value > b.value
- end)
- -- Starte die Liste bei Zeile 3
- i = 3
- for _, player in ipairs(playerList) do
- -- Überprüfe, ob die Zahl größer als 365 ist
- if player.value <= 365 then
- -- Abwechselnde Farben für die Zeilen
- if i % 2 == 0 then
- mon.setTextColor(colors.gray)
- else
- mon.setTextColor(colors.lightGray)
- end
- -- Schreibe den Namen und die Zahl in die Liste
- mon.setCursorPos(1, i)
- mon.write(player.name)
- mon.setCursorPos(w - 2, i)
- local textValue = tostring(player.value) -- Konvertiere die Zahl wieder in Text
- mon.write(textValue) -- Schreibe den Text auf den Monitor
- i = i + 1
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment