Kodi Community Forum

Full Version: How to make service result available to be used on the skin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

This is my very first attempt with Kodi services and skins.

I already modified my Titan skin to enable a third row underneath the time and date to display my IP.

My goal, is to display the external IP and location here, and so I also created a service that does exactly that and prints the result in the log file for now.

The code of the service is the following:

Code:
import xbmcaddon
import xbmcgui
import subprocess
import urllib
import requests
import json
import xbmc
import time

addon       = xbmcaddon.Addon()
addonname   = addon.getAddonInfo('name')


def check_location():
    send_url = 'http://freegeoip.net/json'
    r = requests.get(send_url)
    j = json.loads(r.text)
    city = j['city']
    return "Currently connected from: " + city;

def check_ip():
    public_ip = subprocess.check_output(["ifconfig `ip route get 8.8.8.8 | grep 8.8.8.8 | cut -d' ' -f5` | grep \'inet \' | awk -F'[: ]+' '{ print $4 }'"], shell=True);
    result = ("Your IP is : %s " % public_ip);
    return result;


if __name__ == '__main__':
    monitor = xbmc.Monitor()
    while not monitor.abortRequested():
        if monitor.waitForAbort(2):
            break
        test = "Check IP and Location" + check_ip() + check_location();
        xbmc.log(test,  level=xbmc.LOGDEBUG)

and the result printed on the log file is exactly what I expect.

The part of the skin that I edited is the IncludeHeader.xml, and I edited it like this:


Code:
<include name="TimeInfoCompact">
        <control type="group">
            <control type="label">
                <right>50</right>
                <top>10</top>
                <align>right</align>
                <width>300</width>
                <info>System.Time</info>
                <font>Bold30</font>
                <textcolor>$INFO[Skin.String(HeaderTextColor)]</textcolor>
                <shadowcolor>$INFO[Skin.String(HeaderTextShadowColor)]</shadowcolor>
            </control>
            <control type="label">
                <right>50</right>
                <top>40</top>
                <align>right</align>
                <width>500</width>
                <info>System.Date</info>
                <font>Reg26</font>
                <textcolor>$INFO[Skin.String(HeaderTextColor)]</textcolor>
                <shadowcolor>$INFO[Skin.String(HeaderTextShadowColor)]</shadowcolor>
            </control>
            <control type="label">
                <right>50</right>
                <top>70</top>
                <align>right</align>
                <width>500</width>
                <info>Network.IPAddress</info>
                <font>Reg20</font>
                <textcolor>$INFO[Skin.String(HeaderTextColor)]</textcolor>
                <shadowcolor>$INFO[Skin.String(HeaderTextShadowColor)]</shadowcolor>
            </control>
        </control>
    </include>

the last label is printing Network.IPAddress.
How do I make this print the result of my service?

Again, this is the first time for me, so any type of help would be really really appreciated. Thanks a lot
You can set the ip in a window property in the script and display that in the skin.
Hi, thanks. Can you please give me a quick example please?
Thanks, i'll give it a go Smile