示例#1
0
def execute_refresh_clicklog(times=30):
    """从redis读取访问记录刷入mysql"""
    key = "passport:AccessCount:clicklog"
    while times > 0:
        data = redis.lpop(key)
        try:
            data = json.loads(data)
        except:
            cli_logger.info("no clicklog")
            break
        else:
            browserType, browserDevice, browserOs, browserFamily = parse_userAgent(
                data["agent"])
            sql = "INSERT INTO sys_clicklog set url=%s, ip=%s, agent=%s, method=%s, status_code=%s, referer=%s, isp=%s, browserType=%s, browserDevice=%s, browserOs=%s, browserFamily=%s, clickTime=%s, TimeInterval=%s"
            try:
                mysql.insert(sql, data.get("url"), data.get("ip"),
                             data.get("agent"), data.get("method"),
                             data.get("status_code"), data.get("referer"),
                             getIpArea(data.get("ip")), browserType,
                             browserDevice, browserOs, browserFamily,
                             int(data.get("clickTime") or 0),
                             data.get("TimeInterval"))
            except Exception, e:
                cli_logger.warn(e, exc_info=True)
            else:
                cli_logger.info("refresh_clicklog is ok")
示例#2
0
 def __check_hasUser(uid):
     """检查是否存在账号"""
     if uid and len(uid) == 22:
         sql = "SELECT count(uid) FROM user_auth WHERE uid=%s"
         try:
             data = mysql.get(sql, uid)
         except Exception, e:
             cli_logger.warn(e, exc_info=True)
         else:
             if data and isinstance(data, dict):
                 return True if data.get('count(uid)', 0) > 0 else False
示例#3
0
文件: cli.py 项目: ahmachan/passport
def execute_refresh_loginlog(times=30):
    """从redis读取登录记录刷入mysql"""
    key = "passport:loginlog"
    while times > 0:
        data = redis.lpop(key)
        try:
            data = json.loads(data)
        except:
            cli_logger.info("no loginlog")
        else:
            browserType, browserDevice, browserOs, browserFamily = parse_userAgent(data["user_agent"])
            login_area = getIpArea(data["login_ip"])
            sql = "INSERT INTO user_loginlog (uid, login_type, login_ip, login_area, login_time, user_agent, browser_type, browser_device, browser_os, browser_family) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
            try:
                mysql.insert(sql, data["uid"], data["identity_type"], data["login_ip"], login_area, data["login_time"], data["user_agent"], browserType, browserDevice, browserOs, browserFamily)
            except Exception, e:
                cli_logger.warn(e, exc_info=True)
            else:
                cli_logger.info("refresh_loginlog is ok")