Beispiel #1
0
CACHE_FILE = os.path.join(USER_DATA_DIR, "cache")
COOKIE_FILE = os.path.join(USER_DATA_DIR, "lwp_cookies.dat")
expire_after = timedelta(hours=CACHE_TIME)

if not os.path.exists(USER_DATA_DIR):
    os.makedirs(USER_DATA_DIR)

s = CachedSession(
    CACHE_FILE,
    allowable_methods=("GET", "POST"),
    expire_after=expire_after,
    old_data_on_error=True,
    ignored_parameters=["data"],
)
s.hooks = {"response": lambda r, *args, **kwargs: r.raise_for_status()}
s.cookies = LWPCookieJar(filename=COOKIE_FILE)
if os.path.isfile(COOKIE_FILE):
    s.cookies.load(ignore_discard=True, ignore_expires=True)

data_url = "http://swiftstreamz.com/SwiftPanel/apiv1.php"
cat_url = "http://swiftstreamz.com/SwiftPanel/apiv1.php?get_category"
list_url = "http://swiftstreamz.com/SwiftPanel/apiv1.php?get_channels_by_cat_id={0}"


def quote(s, safe=""):
    return orig_quote(s.encode("utf-8"), safe.encode("utf-8"))


def unquote(s):
    return orig_unquote(s).decode("utf-8")