Ejemplo n.º 1
0
def load_search_history_person():
    history = []
    filename = get_userdata_dir() + "search_history_person.txt"
    try:
        with open(filename, "r") as file:
            for line in file:
                item = line[:-1]
                history.append(item)
    except IOError:
        history = []
    return history
Ejemplo n.º 2
0
def delete_search_person(query):
    filename = get_userdata_dir() + "search_history_person.txt"
    history = load_search_history_person()
    for item in history:
        if item == query:
            history.remove(item)
    try:
        with open(filename, "w") as file:
            for item in history:
                file.write('%s\n' % item)
    except IOError:
        pass
    xbmc.executebuiltin('Container.Refresh')
Ejemplo n.º 3
0
def set_others(showId, val):
    filename = get_userdata_dir() + "favourites.txt"
    favourites = get_favourites(others=-1)
    for key in favourites:
        if key == showId:
            favourites[key].update({"others": int(val)})
    try:
        with codecs.open(filename, "w", encoding="utf-8") as file:
            data = json.dumps(favourites)
            file.write('%s\n' % data)
    except IOError:
        xbmcgui.Dialog().notification("ČRo",
                                      "Problém při uložení oblíbených pořadů",
                                      xbmcgui.NOTIFICATION_ERROR, 4000)
    xbmc.executebuiltin('Container.Refresh')
Ejemplo n.º 4
0
def get_favourites(others=0):
    filename = get_userdata_dir() + "favourites.txt"
    try:
        with open(filename, "r") as file:
            for line in file:
                item = line[:-1]
                data = json.loads(item)
    except IOError:
        data = {}
    for key in list(data):
        if others == 0 and "others" in data[key] and data[key]["others"] == 1:
            del data[key]
        if others == 1 and ("others" not in data[key]
                            or data[key]["others"] == 0):
            del data[key]
    return data
Ejemplo n.º 5
0
def open_db():
    global db, version
    db = sqlite3.connect(get_userdata_dir() + "listened.db", timeout=20)
    db.execute(
        'CREATE TABLE IF NOT EXISTS version (version INTEGER PRIMARY KEY)')
    db.execute(
        'CREATE TABLE IF NOT EXISTS listened (episodeId VARCHAR PRIMARY KEY, showId VARCHAR)'
    )
    row = None
    for row in db.execute('SELECT version FROM version'):
        version = row[0]
    if not row:
        db.execute('INSERT INTO version VALUES (?)', [current_version])
        db.commit()
        version = current_version
    if version != current_version:
        version = migrate_db(version)
    db.commit()
Ejemplo n.º 6
0
def save_search_history_person(query):
    max_history = int(addon.getSetting("search_history"))
    cnt = 0
    history = []
    filename = get_userdata_dir() + "search_history_person.txt"
    try:
        with open(filename, "r") as file:
            for line in file:
                item = line[:-1]
                history.append(item)
    except IOError:
        history = []
    history.insert(0, query)
    with open(filename, "w") as file:
        for item in history:
            cnt = cnt + 1
            if cnt <= max_history:
                file.write('%s\n' % item)
Ejemplo n.º 7
0
def delete_favourites(showId):
    filename = get_userdata_dir() + "favourites.txt"
    favourites = get_favourites(others=-1)
    err = 0
    if showId in favourites.keys():
        del favourites[showId]
        try:
            with codecs.open(filename, "w", encoding="utf-8") as file:
                data = json.dumps(favourites)
                file.write('%s\n' % data)
        except IOError:
            err = 1
            xbmcgui.Dialog().notification(
                "ČRo", "Problém při uložení oblíbených pořadů",
                xbmcgui.NOTIFICATION_ERROR, 4000)
        if err == 0:
            xbmcgui.Dialog().notification("ČRo",
                                          "Pořad byl odebrán z oblíbených",
                                          xbmcgui.NOTIFICATION_INFO, 4000)
        xbmc.executebuiltin('Container.Refresh')
Ejemplo n.º 8
0
def toogle_station(stationId):
    filename = get_userdata_dir() + "stations.txt"
    stations, stations_nums = get_stations(filtered=0)
    for key in stations:
        if stations[key]["id"] == stationId:
            if int(stations[key]["enabled"]) == 1:
                stations[key]["enabled"] = 0
            else:
                stations[key]["enabled"] = 1
    try:
        with codecs.open(filename, "w", encoding="utf-8") as file:
            data = json.dumps({
                "stations": stations,
                "stations_nums": stations_nums,
                "valid_to": int(time.time()) + 60 * 60 * 24
            })
            file.write('%s\n' % data)
    except IOError:
        xbmcgui.Dialog().notification("ČRo", "Problém při uložení stanic",
                                      xbmcgui.NOTIFICATION_ERROR, 4000)
    xbmc.executebuiltin('Container.Refresh')
Ejemplo n.º 9
0
def add_favourites(showId, others):
    filename = get_userdata_dir() + "favourites.txt"
    favourites = get_favourites(others=-1)
    err = 0
    if showId not in favourites.keys():
        show = get_show(showId)
        if int(others) == 1:
            show.update({"others": 1})
        favourites.update({showId: show})
        try:
            with codecs.open(filename, "w", encoding="utf-8") as file:
                data = json.dumps(favourites)
                file.write('%s\n' % data)
        except IOError:
            err = 1
            xbmcgui.Dialog().notification(
                "ČRo", "Problém při uložení oblíbených pořadů",
                xbmcgui.NOTIFICATION_ERROR, 4000)
        if err == 0:
            xbmcgui.Dialog().notification("ČRo",
                                          "Pořad byl přidán do oblíbených",
                                          xbmcgui.NOTIFICATION_INFO, 4000)
Ejemplo n.º 10
0
def get_stations(filtered=1):
    stations = {}
    stations_nums = {}
    max_num = 0

    not_found = 0
    valid_to = -1
    filename = get_userdata_dir() + "stations.txt"
    try:
        with codecs.open(filename, "r", encoding="utf-8") as file:
            for line in file:
                item = line[:-1]
                data = json.loads(item)
                stations = data["stations"]
                stations_nums_str = data["stations_nums"]
                for num in stations_nums_str.keys():
                    stations_nums.update({int(num): stations_nums_str[num]})
                valid_to = data["valid_to"]
    except IOError:
        not_found = 1
    max_num = len(stations_nums)
    if not_found == 1 or valid_to < int(time.time()):
        data = call_api(url="https://api.mujrozhlas.cz/stations")
        if "err" in data:
            xbmcgui.Dialog().notification("ČRo", "Problém při načtení stanic",
                                          xbmcgui.NOTIFICATION_ERROR, 4000)
            sys.exit()
        if "data" in data and len(data["data"]) > 0:
            for station in data["data"]:
                if station["attributes"]["shortTitle"] not in stations.keys():
                    max_num = max_num + 1
                    stations_nums.update(
                        {max_num: station["attributes"]["shortTitle"]})
                    if "url" in station["attributes"]["asset"]:
                        img = station["attributes"]["asset"]["url"]
                    else:
                        img = ""
                    stations.update({
                        station["attributes"]["shortTitle"]: {
                            "id": station["id"],
                            "title": station["attributes"]["shortTitle"],
                            "img": img,
                            "enabled": 1
                        }
                    })
            try:
                with codecs.open(filename, "w", encoding="utf-8") as file:
                    data = json.dumps({
                        "stations":
                        stations,
                        "stations_nums":
                        stations_nums,
                        "valid_to":
                        int(time.time()) + 60 * 60 * 24
                    })
                    file.write('%s\n' % data)
            except IOError:
                xbmcgui.Dialog().notification("ČRo",
                                              "Problém při uložení stanic",
                                              xbmcgui.NOTIFICATION_ERROR, 4000)
        else:
            xbmcgui.Dialog().notification("ČRo", "Problém při načtení stanic",
                                          xbmcgui.NOTIFICATION_ERROR, 4000)
            sys.exit()
    if int(filtered) == 1:
        for num in sorted(stations_nums.keys()):
            if int(stations[stations_nums[num]]["enabled"]) == 0:
                del stations[stations_nums[num]]
                del stations_nums[num]
    return stations, stations_nums