Example #1
0
def updateGroups(groups, groupkey, uri):
    cached = GET("Group", groups, "_")
    if cached is None:
        cached = {}

    ID = 0
    for items in cached.values():
        if items["ID"] > ID:
            ID = items["ID"]

    threads = []

    req = JSONRPC("Control/RecordingGroups/Television/" + groups, "")
    for m in req:
        group = m[groupkey]
        if group in cached:
            cm = cached[group]
            if (
                cm["LatestProgramStartTime"] == m["LatestProgramStartTime"]
                and cm["RecordingsCount"] == m["RecordingsCount"]
            ):
                continue
            m["ID"] = cm["ID"]
        else:
            ID = ID + 1
            m["ID"] = ID

        cached[group] = m

        t = Thread(target=threadFine(updateGroup), args=(groups, group, m["ID"], uri))
        t.m = m
        t.start()
        threads.append(t)

    for t in threads:
        t.join()
        t.fine
        m = t.m
        li = GET("Group", groups, m["ID"]).values()
        li = sorted(li, key=operator.itemgetter("ProgramStartTime"), reverse=True)
        m["Latest"] = li[0] if len(li) > 0 else None

    PUT("Group", groups, "_", cached)