Exemple #1
0
def cacheTopn():
    ret = getAppTopnSids(getAppids(), TOPN)
    top1s = []
    for r in ret:
        appid = r["appid"]
        sids = r["sids"]
        # 单个应用的前12名
        top12 = json.dumps([{"sids":sids, "appid":appid}])
        # 所有上线应用的第一名
        top1s.append({"sids":[sids[0]] if sids else [], "appid":appid})
        mc.set(str(appid), top12)
    mc.set("top1s", json.dumps(top1s))
Exemple #2
0
def getAppids():
    appids = mc.get("APPIDS")
    if not appids:
        try:
            host = random.choice(BROKER_HOST)
            url = host + SUBFIX
            u = urllib.urlopen(url)
            appids = json.loads(u.read())
            mc.set("APPIDS", appids, APPIDS_CACHE_TIME)
            syslog.syslog("get from url")
        except:
            appids = APPIDS
            syslog.syslog("get from const")
    else:
        syslog.syslog("get from cache")
    return appids