コード例 #1
0
    def total_server(self, server):
        """查询服务器"""
        db_config = server_util.str_to_dbconfig(server.db_connect)
        connect = get_connection(db_config)
        cursor = connect.cursor()
        level_map = {}
        try:
            start_time = None
            while True:
                where = "1=1"
                if start_time:
                    where = "reg_time > '%s'" % start_time
                sql = "select reg_time, level from user where %s order by reg_time asc limit 10000" % where

                infos = cursor.fetchall(sql)
                if not infos:
                    break

                self.log("size:[%s], start_time[%s]" %
                         (len(infos), start_time))
                start_time = infos[-1]["reg_time"]
                for info in infos:
                    level = info["level"]
                    total = level_map.get(level, 0)
                    total += 1
                    level_map[level] = total

        finally:
            cursor.close()

        stat_user_level = StatUserLevel()
        stat_user_level.server_id = server.server_id
        stat_user_level.data = json.dumps(level_map)
        stat_user_level.date = datetime.now().strftime("%Y-%m-%d")
        stat_user_level.persist()
コード例 #2
0
def report_log(client_id, server_id, ret, command_type, output, params):
    client_run_log = ClientRunLog()
    client_run_log.client_id = client_id
    client_run_log.status = ret
    client_run_log.content = output
    client_run_log.extinfo = json.dumps(params)
    client_run_log.command_type = command_type
    client_run_log.server_id = server_id
    client_run_log.persist()
コード例 #3
0
def add_command(client_ids, command):
    client_id_list = client_ids.split(",")
    command_type = int(command["command_type"])
    command["command_type"] = command_type
    command_json = json.dumps(command)
    for client_id in client_id_list:
        logging.debug("client_id[%s], command[%s]" % (client_id, command))
        client = Client.load(id=client_id)
        if client:
            client.command = command_json
            client.persist()
コード例 #4
0
ファイル: views.py プロジェクト: smsg-game/smsg-server
def get_server_list(request):
    partner_id = request.GET.get('partnerId', 1001)
    server_list = server_business.get_partner_server_list(partner_id)
    server_info_list = []
    for server in server_list:
        info = {}
        info["serverName"] = server["server_name"]
        info["serverPort"] = server["server_port"]
        info["status"] = server["server_status"]
        info["serverId"] = server["server_id"]
        info["openTime"] = int(time.mktime(server["open_time"].timetuple())) * 1000
        server_info_list.append(info)
    data = {"rc": 1000, "servers": json.dumps(server_info_list, False)}
    return json_response(data, False)
コード例 #5
0
def get_server_list(request):
    partner_id = request.GET.get('partnerId', 1001)
    server_list = server_business.get_partner_server_list(partner_id)
    server_info_list = []
    for server in server_list:
        info = {}
        info["serverName"] = server["server_name"]
        info["serverPort"] = server["server_port"]
        info["status"] = server["server_status"]
        info["serverId"] = server["server_id"]
        info["openTime"] = int(time.mktime(
            server["open_time"].timetuple())) * 1000
        server_info_list.append(info)
    data = {"rc": 1000, "servers": json.dumps(server_info_list, False)}
    return json_response(data, False)
コード例 #6
0
 def total_server(self, server):
     """查询服务器"""
     db_config = server_util.str_to_dbconfig(server.db_connect)
     connect = get_connection(db_config)
     cursor = connect.cursor()
     infos = None
     try:
         sql = "select lodo_id, username, level, exp from user order by level desc, exp desc limit 100"
         infos = cursor.fetchall(sql)
         infos = infos.to_list()
     finally:
         cursor.close()
         
     stat_user_level_rank = StatUserLevelRank()
     stat_user_level_rank.server_id = server.server_id
     stat_user_level_rank.data = json.dumps(infos)
     stat_user_level_rank.date = datetime.now().strftime("%Y-%m-%d")
     stat_user_level_rank.persist()
コード例 #7
0
    def total_server(self, server):
        """查询服务器"""
        db_config = server_util.str_to_dbconfig(server.db_connect)
        connect = get_connection(db_config)
        cursor = connect.cursor()
        infos = None
        try:
            sql = "select lodo_id, username, level, exp from user order by level desc, exp desc limit 100"
            infos = cursor.fetchall(sql)
            infos = infos.to_list()
        finally:
            cursor.close()

        stat_user_level_rank = StatUserLevelRank()
        stat_user_level_rank.server_id = server.server_id
        stat_user_level_rank.data = json.dumps(infos)
        stat_user_level_rank.date = datetime.now().strftime("%Y-%m-%d")
        stat_user_level_rank.persist()
コード例 #8
0
def data_sync(server_id, sync_type=1, table=None, sqls=[]):
    """数据同步"
    @param sync_type: 同步类型1:修改 ;2:新增 ;3:删除;4:全表同步 
    @param table:同步的表
    @param sqls:同步的sql
    """
    server = Server.load(server_id=server_id)
    host = server.server_host

    path = "/gameApi/dataSync.do"
    logging.debug("host:[%s], path[%s]" % (host, path))
    data = {"syncType": sync_type, "table": table, "sqls": json.dumps(sqls)}

    post = Post(data, host, path, port=8088)
    content = post.submit(result_keyword=None, get_content=True, debug=True)
    try:
        info = json.loads(content)
        return info.get("rc", 3000) == 1000
    except:
        logging.debug("bad json format:[%s]" % content)
        return False
コード例 #9
0
def data_sync(server_id, sync_type=1, table=None, sqls=[]):
    """数据同步"
    @param sync_type: 同步类型1:修改 ;2:新增 ;3:删除;4:全表同步 
    @param table:同步的表
    @param sqls:同步的sql
    """
    server = Server.load(server_id=server_id)
    host = server.server_host

    path = "/gameApi/dataSync.do"
    logging.debug("host:[%s], path[%s]" % (host, path))
    data = {"syncType": sync_type, "table": table, "sqls": json.dumps(sqls)}

    post = Post(data, host, path, port=8088)
    content = post.submit(result_keyword=None, get_content=True, debug=True)
    try:
        info = json.loads(content)
        return info.get("rc", 3000) == 1000
    except:
        logging.debug("bad json format:[%s]" % content)
        return False
コード例 #10
0
def json_response(data, ensure_ascii=True):
    return HttpResponse(json.dumps(data, ensure_ascii))
コード例 #11
0
def system_mail_approve(system_mail_id, approve_user, approve=False):
    system_mail = get_system_mail(system_mail_id)
    if system_mail.status != 0:
        return
    else:
        system_mail.status = 3
        system_mail.persist()
    system_mail.approve_user = approve_user
    system_mail.approve_time = datetime.now()
    result_map = {}
    if approve:
        server_ids = system_mail.server_ids.split(",")
        send_server_ids = []
        for server_id in server_ids:
            mail_info = {}
            mail_info["title"] = system_mail.title
            mail_info["content"] = system_mail.content
            mail_info["toolIds"] = system_mail.tool_ids
            mail_info["lodoIds"] = system_mail.lodo_ids
            mail_info["target"] = system_mail.target
            mail_info["sourceId"] = system_mail.system_mail_id
            if system_mail.date:
                mail_info["date"] = int(
                    time.mktime(system_mail.date.timetuple())) * 1000
            else:
                mail_info["date"] = int(time.time())

            mail_info["partner"] = system_mail.partner_id
            server = Server.load(server_id=server_id)
            url = "http://" + server.server_host + ":8088/gameApi/sendMail.do?"
            params = {}
            for k, v in mail_info.iteritems():
                if isbasestring(v):
                    params[k] = v.encode("utf8")
                else:
                    params[k] = v
            url = url + urllib.urlencode(params)
            logging.info("server:%s,url:%s" % (server_id, url))

            result_map[server_id] = 0
            approve_info = {}
            try:
                ret_val = urllib.urlopen(url).read()
                approve_info[server_id] = ret_val
                result = json.loads(ret_val)
                if result.get("rt") == 1000:
                    send_server_ids.append(server_id)
                    result_map[server_id] = 1
                else:
                    logging.warn(u"邮件发送失败.server_id[%s], msg[%s]" %
                                 (server_id, result.get("msg")))
            except:
                approve_info[server_id] = traceback.format_exc()
                logging.error(traceback.format_exc())

        system_mail.status = 1
        system_mail.send_server_ids = ",".join(send_server_ids)
        system_mail.approve_info = json.dumps(approve_info)
    else:
        system_mail.status = 2

    system_mail.persist()

    return 1, result_map
コード例 #12
0
def test2():
    data = {}
    data["n1"] = 1
    data["n2"] = 2
    print data.get("n2", 0) / data.get("n1", 1)


if __name__ == '__main__':
    pass
    pass
    data = {}
    infos = api_business.get_tool_use_info('d1', '2013-10-19')
    for i in infos:
        if i.server_id in data.keys():
            temp = []
            temp.append(i.tool_type)
            temp.append(i.tool_id)
            temp.append(i.use_type)
            temp.append(i.tool_num)
            data[i.server_id].append(temp)
        else:
            data[i.server_id] = []
            temp = []
            temp.append(i.tool_type)
            temp.append(i.tool_id)
            temp.append(i.use_type)
            temp.append(i.tool_num)
            data[i.server_id].append(temp)

    print json.dumps(data)
コード例 #13
0
def system_mail_approve(system_mail_id, approve_user, approve=False):
    system_mail = get_system_mail(system_mail_id)
    if system_mail.status != 0:
        return
    else:
        system_mail.status = 3
        system_mail.persist()
    system_mail.approve_user = approve_user
    system_mail.approve_time = datetime.now()
    result_map = {}
    if approve:
        server_ids = system_mail.server_ids.split(",")
        send_server_ids = []
        for server_id in server_ids:
            mail_info = {}
            mail_info["title"] = system_mail.title
            mail_info["content"] = system_mail.content
            mail_info["toolIds"] = system_mail.tool_ids
            mail_info["lodoIds"] = system_mail.lodo_ids
            mail_info["target"] = system_mail.target
            mail_info["sourceId"] = system_mail.system_mail_id 
            if system_mail.date:
                mail_info["date"] = int(time.mktime(system_mail.date.timetuple())) * 1000
            else:
                mail_info["date"] = int(time.time())
                
            mail_info["partner"] = system_mail.partner_id 
            server = Server.load(server_id=server_id)
            url = "http://" + server.server_host + ":8088/gameApi/sendMail.do?"
            params = {}
            for k, v in mail_info.iteritems():
                if isbasestring(v):
                    params[k] = v.encode("utf8")
                else:
                    params[k] = v
            url = url + urllib.urlencode(params)
            logging.info("server:%s,url:%s" % (server_id, url))
            
            result_map[server_id] = 0
            approve_info = {}
            try:
                ret_val = urllib.urlopen(url).read()
                approve_info[server_id] = ret_val
                result = json.loads(ret_val)
                if result.get("rt") == 1000:
                    send_server_ids.append(server_id)
                    result_map[server_id] = 1
                else:
                    logging.warn(u"邮件发送失败.server_id[%s], msg[%s]" % (server_id, result.get("msg")))
            except:
                approve_info[server_id] = traceback.format_exc()
                logging.error(traceback.format_exc())
                
                
                
        system_mail.status = 1
        system_mail.send_server_ids = ",".join(send_server_ids)
        system_mail.approve_info = json.dumps(approve_info)
    else:
        system_mail.status = 2
        
    system_mail.persist()
    
    return 1, result_map
コード例 #14
0
ファイル: render.py プロジェクト: smsg-game/smsg-server
def json_response(data, ensure_ascii=True):
    return HttpResponse(json.dumps(data, ensure_ascii))
コード例 #15
0
def report_result(client_id, data):
    client = Client.load(id=client_id)
    logging.debug("report_result, client_id[%s], data[%s]" % (client_id, data))
    if client:
        client.last_command_report = json.dumps(data)
        client.persist()
コード例 #16
0
ファイル: test.py プロジェクト: smsg-game/smsg-server
    print data.get("n2", 0) / data.get("n1", 1)

if __name__ == '__main__':
    pass
    pass
    data = {}
    infos = api_business.get_tool_use_info('d1', '2013-10-19')
    for i in infos:
        if i.server_id in data.keys():
            temp = []
            temp.append(i.tool_type)
            temp.append(i.tool_id)
            temp.append(i.use_type)
            temp.append(i.tool_num)
            data[i.server_id].append(temp)
        else:
            data[i.server_id] = []
            temp = []
            temp.append(i.tool_type)
            temp.append(i.tool_id)
            temp.append(i.use_type)
            temp.append(i.tool_num)
            data[i.server_id].append(temp)
  
    print json.dumps(data)