コード例 #1
0
def clear_caches(refreshed, silent):

    xfiles = [fvod]

    try:
        files = [
            f for f in os.listdir(cache_dir) if (cache_dir + f not in xfiles)
        ]
        for f in files:
            os.remove(cache_dir + f)

        if refreshed:
            ok = (xbmcgui.Dialog().yesno(
                'Clear: Caches', '\n', '\n',
                'Do you also want to generate a new token ?') > 0)
            if ok:
                dummy = get_genres()
                dummy = get_channels()

        if not silent:
            notify('IPTV',
                   '[COLOR lime]Process:  DONE![/COLOR]',
                   icon='DefaultIconInfo.png',
                   sec=3)

    except Exception as e:
        if not silent:
            notify('[COLOR red]Clear Caches:  FAIL![/COLOR]',
                   str(e),
                   icon='DefaultIconError.png',
                   sec=3)
コード例 #2
0
 def __notify__(result):
     message = None
     if isinstance(result, Exception):
         message = "session: request error [{}]".format(result)
         log(message, LOGERROR)
     elif isinstance(result, dict):
         message = result.get("error")
     if message:
         notify(message, icon=ICONERROR)
         return True
     return False
コード例 #3
0
ファイル: pvr.py プロジェクト: kens13/Kens13_Repo
def simple_settings(epg):
    import xml.etree.ElementTree as ET
    from stalker import fm3u

    pvr_dir = os.path.join(user_dir, 'addon_data/pvr.iptvsimple/')
    if not os.path.isdir(pvr_dir): os.mkdir(pvr_dir)
    fpvr = os.path.join(pvr_dir, 'settings.xml')

    m3u_src, m3u_type, m3u_id = [fm3u, '0', 'm3uPath']

    xbmc.executeJSONRPC(
        '{"jsonrpc": "2.0", "method": "Addons.SetAddonEnabled", "params": { "addonid": "pvr.iptvsimple", "enabled": false }, "id": 1 }'
    )

    try:
        with open(fpvr, 'r') as f:
            xml = f.read()
    except:
        return

    root = ET.fromstring(xml)
    tags = root.findall("setting")

    settings = {
        m3u_id: m3u_src,
        'epgUrl': epg,
        'epgTimeShift': str(gmt_hour),
        'epgTSOverride': 'true',
        'm3uPathType': m3u_type,
        'epgPathType': '1',
        'm3uCache': 'false',
        'epgCache': 'false'
    }

    for i in tags:
        if i.attrib['id'] in settings:
            i.attrib['value'] = settings[i.attrib['id']]

    xml = ET.tostring(root).replace("><", ">\n<")
    with open(fpvr, 'w') as f:
        f.write(xml)

    notify('[COLOR orange]PVR Client[/COLOR]',
           '[COLOR lime]Auto Settings:  DONE![/COLOR]',
           icon='DefaultIconInfo.png',
           sec=2)
    xbmc.executeJSONRPC(
        '{"jsonrpc": "2.0", "method": "Addons.SetAddonEnabled", "params": { "addonid": "pvr.iptvsimple", "enabled": true }, "id": 1 }'
    )
コード例 #4
0
def clearSearchHistory(type=None, update=False):
    search_history = _loadSearchHistory()
    if type:
        search_history[type].clear()
    else:
        search_history.clear()
    _dumpSearchHistory(search_history)
    if type:
        containerRefresh()
    else:
        notify(30114, time=2000)
        if update:
            containerUpdate(__search_url__, "replace")
        else:
            containerRefresh()
コード例 #5
0
 def get(self, url, **kwargs):
     log("youtube.url: {}".format(buildUrl(url, **kwargs.get("params",
                                                             {}))))
     try:
         response = requests.get(url,
                                 headers=self.__headers__,
                                 timeout=(9.05, 30.0),
                                 **kwargs)
     except requests.Timeout as error:
         message = "youtube: {}".format(error)
         log(message, LOGERROR)
         notify(message, icon=ICONERROR)
     else:
         response.raise_for_status()
         return response.text
コード例 #6
0
def create_user(bridge_ip, notify=True):
    device = 'kodi#ambilight'
    data = '{{"devicetype": "{}"}}'.format(device)

    res = 'link button not pressed'
    while 'link button not pressed' in res:
        if notify:
            import tools
            tools.notify('Kodi Hue', 'Press link button on bridge')
        req = requests.post('http://{}/api'.format(bridge_ip), data=data)
        res = req.text
        time.sleep(3)

    res = req.json()
    username = res[0]['success']['username']

    return username
コード例 #7
0
def user_exists(bridge_ip, bridge_user, notify=True):
    req = requests.get('http://{}/api/{}/config'.format(
        bridge_ip, bridge_user))
    res = req.json()

    success = True
    try:
        success = bridge_user in res['whitelist']
    except KeyError:
        success = False

    if notify:
        import tools
        if success:
            tools.notify("Kodi Hue", "Connected")
        else:
            tools.notify("Kodi Hue", "Could not connect to bridge")

    return success
コード例 #8
0
def discover_hue_bridge(hue):
    notify("Hue Bridge Discovery", "starting")
    hue_ip = bridge.discover()
    if hue_ip is not None:
        notify("Hue Bridge Discovery", "Found bridge at: %s" % hue_ip)
        username = bridge.create_user(hue_ip)
        hue.settings.update(bridge_ip=hue_ip)
        hue.settings.update(bridge_user=username)
        hue.settings.update(connected="true")
        hue.connected = True
        notify("Hue Bridge Discovery", "Finished")
    else:
        notify("Hue Bridge Discovery", "Failed. Could not find bridge.")
コード例 #9
0
def discover_hue_bridge(hue):
    notify("Hue Bridge Discovery", "starting")
    hue_ip = bridge.discover()
    if hue_ip is not None:
        notify("Hue Bridge Discovery", "Found bridge at: %s" % hue_ip)
        username = bridge.create_user(hue_ip)
        hue.settings.update(bridge_ip=hue_ip)
        hue.settings.update(bridge_user=username)
        hue.settings.update(connected="true")
        hue.connected = True
        notify("Hue Bridge Discovery", "Finished")
    else:
        notify("Hue Bridge Discovery", "Failed. Could not find bridge.")
コード例 #10
0
def create_user(bridge_ip, notify=True):
    device = 'kodi#ambilight'
    data = '{{"devicetype": "{}"}}'.format(device)

    res = 'link button not pressed'
    while 'link button not pressed' in res:
        if notify:
            import tools
            tools.notify('Kodi Hue', 'Press link button on bridge')
        req = requests.post('http://{}/api/'.format(bridge_ip), data=data)
        res = req.text
        print("Hue Kodi:", res)
        if res.startswith('405:'):
            return "12345678901234567890"  # home assistant

        time.sleep(3)

    res = req.json()
    username = res[0]['success']['username']

    return username
コード例 #11
0
ファイル: jobs.py プロジェクト: WinjayYu/schedule
def monitor_ip():
    global old_ip
    if not old_ip:
        old_ip = get_old_ip()
    try:
        res = requests.get("https://api.ipify.org?format=json")
        try:
            ip_json = res.json()
            logger.log(ip_json["ip"])
            current_ip = ip_json["ip"]
            if old_ip != current_ip:
                old_ip = current_ip
                notify(token, "ipHasChanged", current_ip)
                os.system("bash ./update_ddns.sh %s" % current_ip)
                set_ip(current_ip)
        except OSError as e:
            logger.error(str(e))
            print("parse json error")
    except Exception as e:
        logger.error(str(e))
        print(e)
        pass
コード例 #12
0
import socket
import time

import lights
import tools

try:
    import requests
except ImportError:
    tools.notify("Kodi Hue", "ERROR: Could not import Python requests")


def user_exists(bridge_ip, bridge_user, notify=True):
    req = requests.get('http://{}/api/{}/config'.format(
        bridge_ip, bridge_user))
    if req.text.startswith("404:"): return True  # home assistant emulator

    res = req.json()

    success = True
    try:
        success = bridge_user in res['whitelist']
    except KeyError:
        success = False

    if notify:
        import tools
        if success:
            tools.notify("Kodi Hue", "Connected")
        else:
            tools.notify("Kodi Hue", "Could not connect to bridge")
コード例 #13
0
import socket
import time

import lights
import tools

try:
    import requests
except ImportError:
    tools.notify("Kodi Hue", "ERROR: Could not import Python requests")


def user_exists(bridge_ip, bridge_user, notify=True):
    req = requests.get('http://{}/api/{}/config'.format(
        bridge_ip, bridge_user))
    res = req.json()

    success = True
    try:
        success = bridge_user in res['whitelist']
    except KeyError:
        success = False

    if notify:
        import tools
        if success:
            tools.notify("Kodi Hue", "Connected")
        else:
            tools.notify("Kodi Hue", "Could not connect to bridge")

    return success
コード例 #14
0
ファイル: run.py プロジェクト: honzajavorek/brno

from drivers import agartha, kafelanka, podzemibrno, poznejbrno, brnonow
from tools import log, notify, slugify
import datetime
import os
import subprocess



active_drivers = (
    agartha,
    kafelanka,
    podzemibrno,
    poznejbrno,
    brnonow,
)



notify('Brno', 'Starting update...')
for driver in active_drivers:
    notify('Brno', 'Starting driver "%s"' % driver.__name__)
    log('driver', driver.__name__)
    driver.run()

notify('Brno', 'Exporting and uploading database...')
filename = '%s/db/%s.sql' % (os.path.dirname(os.path.realpath(__file__)), slugify(datetime.date.today()))
log('dump', filename)
with open(filename, 'w') as f:
    subprocess.Popen(['mysqldump', '-h', 'localhost', '-u', 'dev', '--password=dev', 'brno'], stdout=f).wait()
コード例 #15
0
 def __raise__(self, error):
     if not isinstance(error, Exception):
         error = Exception(error)
     notify("{}".format(error), icon=ICONERROR)
     raise error