Kodi Community Forum

Full Version: KODI 15 & 16: Set variable with psycopg2?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there,

I'm modifying an old service script from kodi 15.1, used to load some video and other stuff on the screens of my restaurant.
From time to time I need to update a variable set on a txt file.
Now I'm trying to pick it up directly from a database on Kodi 16.1, like I do with other Python script I have, but even if Kodi doesn't show errors in log the var is not updated.
Here is the snippet of the working code I used on 15.1:

Code:
def getVarFromFile(filename):
    f = open(filename)
    global data
    data = imp.load_source('data', '', f)
    f.close()

getVarFromFile('/home/effe/var.txt')
xbmc.executebuiltin("Skin.SetString(tempo, {0})".format(data.wait_time))

And this is what I would like to archive in 16.1:

Code:
import psycopg2.extras,
def get_time_var():
    try:
        con = psycopg2.connect(host='localhost', database='DB01', user='xxxx', password='xxxxxxx')
        cur = con.cursor()
        cur.execute('SELECT avg_minutes FROM public.divina_custos order by id ASC limit 1')
        data = cur.fetchone()
        global data2
        data2 = str(data[0])
        
    except psycopg2.DatabaseError, e:
        print 'Error %s' % e
        sys.exit(1)

    finally:
        if con:
            con.close()

get_time_var()
xbmc.executebuiltin("Skin.SetString(tempo, {0})".format(data2))

Loading from a txt works just on 15.1, and both script aren't working on 16.1.

Here's the log. And this is the full script working on 15.1.
I need some clue...

Thanks,

F.