How to refresh data on xbmcgui.WindowDialog?

I'm working on a addon. I want see current foreign exchange rates on top corner of the screen. I've brought the addon up to a point. But I cannot refresh the data automatically.

How to refresh data every 15 seconds on xbmcgui.WindowDialog?

Please help me.

# -*- coding: utf-8 -*-
import xbmc, xbmcplugin, xbmcaddon, xbmcgui
import re
import urllib2
from datetime import datetime
import time, locale, pytz
import platform,os
import json, threading


addon = xbmcaddon.Addon(id=ADDON_ID)

def cek(link):
   req = urllib2.Request(link)
                  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36')
   yanit = urllib2.urlopen(req)
   sonuc = json.load(yanit)

   return sonuc

def convert_datetime_timezone(dt, tz1, tz2):
   tz1 = pytz.timezone(tz1)
   tz2 = pytz.timezone(tz2)
       dt = datetime.strptime(dt,"%Y-%m-%dT%H:%M:%SZ")
       dt = datetime.fromtimestamp(time.mktime(time.strptime(dt, "%Y-%m-%dT%H:%M:%SZ")))
   dt = tz1.localize(dt)
   dt = dt.astimezone(tz2)
   dt = dt.strftime("%c")
   return dt

url = '*,%20%22EURTRY%22)&env=store://'

class MyAddon(xbmcgui.WindowDialog):
   def __init__(self):
       veri = cek(url)
       tarih = veri['query']['created']
       tarih = convert_datetime_timezone(tarih, "UTC", "Europe/Istanbul")

       dolar = []
       euro = []

       for x in veri['query']['results']['rate']:
           if x['id'] == 'USDTRY':
               dolar = x['Rate']
           if x['id'] == 'EURTRY':
               euro = x['Rate']

       self.addControl(xbmcgui.ControlImage(800,20, 500, 100, ""))
       self.list = xbmcgui.ControlList(810, 20, 500, 110, 'font12', '0xFFFFFFFF')

       self.list.addItem('Dolar:               ' + dolar +' TL\nGuncelleme:    ' + tarih)


if __name__ == '__main__':
   myaddon = MyAddon()
   del myaddon
Download addon
You need to run a secondary thread from which you can update your Controls with new data.
Raspberry PI 2 + LibreELEC 8 (Kodi 17)
Samsung Galaxy Tab A 10.1 + Kodi 17 for Android
Thread Rating:
  • 0 Vote(s) - 0 Average

Logout Mark Read Team Forum Stats Members Help
How to refresh data on xbmcgui.WindowDialog?00