# @name XboxGamerscore # @desc Xbox Gamerscore # @author Big Quantum # @version 2.7 class XboxGamerscore var key var score var busy var ticks def init() self.key = "OpenXBL API key here" self.score = "..." self.busy = false self.ticks = 0 end def body(b, s) self.busy = false log("Xbox HTTP status=" + str(s)) if b == nil log("Xbox temporary connection error - keeping last score") return end var m = re.search("\"value\"\\s*:\\s*\"(\\d+)\"", b) if m == nil log("Gamerscore value not found - keeping last score") return end self.score = m[1] log("Gamerscore=" + self.score) end def loop() if self.ticks > 0 self.ticks -= 1 return end if self.busy return end # Alle 10 Minuten aktualisieren self.ticks = 600 self.busy = true http.get( "https://api.xbl.io/v2/account", / b, s -> self.body(b, s), { 'headers': { 'X-Authorization': self.key, 'Accept': 'application/json' }, 'find': "Gamerscore", 'keep': 100 } ) end def draw() clear() # Xbox Icon 4253 if !icon("4253", 0, 0) circle_fill(4, 4, 3, 0x00FF00) end # Gamerscore var tw = text_ink_width(self.score) text( 9 + (width() - 9 - tw) / 2, 6, self.score, 0x00FF00 ) end end return XboxGamerscore()