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")
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")
guid, 2, ctime, 1) except: raise mysql._db.commit() except Exception, e: printcolor(str(e), "red") res.update(msg="Operation failed, rolled back") mysql._db.rollback() else: if __check_hasUser(guid): res.update(msg="Registration success", success=True) else: res.update(msg="Registration failed") else: res.update(msg="Check failed") cli_logger.info(res) return res try: printcolor("请根据提示输入信息以创建管理员用户", "red") email = raw_input("请输入管理员邮箱账号:") password = getpass.getpass("请输入管理员账号密码:") repasswd = getpass.getpass("请确认管理员账号密码:") except KeyboardInterrupt: sys.stdout.write('\n') exit(1) else: if not email_check(email): printcolor("请输入正确的邮箱", "yellow") else: if password != repasswd: