Esempio n. 1
0
 def login(self, mobile, password):
     """
     模拟用户登录
     :param mobile:
     :param password:
     :return:接口返回的json数据
     """
     post_data = {'mobile': '%s' % mobile, 'password': '******' % password}
     headers = {
         "Cache - Control": "no - cache",
         "Content - Type": "text / html;charset = UTF - 8",
         'Accept': 'application/json',
         "Date": "%s" % GetTime().getHeaderTime(),
         "Proxy - Connection": "Keep - alive",
         "Server": "nginx / 1.9.3(Ubuntu)",
         "Transfer - Encoding": "chunked"
     }
     login_url = "http://%s/user/login" % ConfigFile().host()
     request = requests.post(login_url, data=post_data, headers=headers)
     time = GetTime().getCurrentTime()
     status_code = request.status_code
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
     finally:
         log_list = [
             u'登录', u"post", login_url,
             str(post_data), time, status_code, info
         ]
Esempio n. 2
0
 def match_created(self, login, status):
     post_data = {}
     headers = {
         "Cache - Control": "no - cache",
         "Content - Type": "text / html;charset = UTF - 8",
         'Accept': 'application/json',
         'Authorization': login["data"]["auth_token"],
         "Date": "%s" % GetCurrentTime().getHeaderTime(),
         "Proxy - Connection": "Keep - alive",
         "Server": "nginx / 1.9.3(Ubuntu)",
         "Transfer - Encoding": "chunked"
     }
     match_created_url = "http://%s/activity/found/%d" % (
         ConfigFile().host(), status)
     request = requests.get(match_created_url, post_data, headers=headers)
     time = GetCurrentTime().getCurrentTime()
     status_code = request.status_code
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
     finally:
         log_list = [
             u'我发布的比赛', u"get", match_created_url,
             str(post_data), time, status_code, info
         ]  # 单条日志记录
         GetReport().get_report()  # 生成或打开日志文件
         GetReport().record_into_report(log_list)  # 逐条写入日志
Esempio n. 3
0
 def __init__(self):
     config_file = ConfigFile()
     self.tokens = config_file.get_token()
     self.judgement_token = Login().login(
         config_file.judgement()[0],
         config_file.judgement()[1])["data"]["auth_token"]
     self.match_id = config_file.activity_id()
     self.screening = config_file.screening()
Esempio n. 4
0
 def against_pair_token(self):
     """
     按照对阵表排列token
     :return:
     """
     pair_list = Against().against(self.judgement_token, self.match_id,
                                   self.screening)
     uid_token_bonds = ConfigFile().uid_token_bonds()
     against_pair_token = []
     for pair in pair_list:
         if pair[0] == 0:
             token0 = "0"
             token1 = uid_token_bonds[int(pair[1])]
         elif pair[1] == 0:
             token0 = uid_token_bonds[int(pair[0])]
             token1 = "0"
         else:
             token0 = uid_token_bonds[int(pair[0])]
             token1 = uid_token_bonds[int(pair[1])]
         against_pair_token.append([token0, token1])
     return against_pair_token
Esempio n. 5
0
 def qq_login(self, openid):
     """
     QQ登录
     :param openid:
     :return:
     """
     post_data = {
         "type": "qq",  # QQ: 'qq'; 微信: 'weixin'
         "openid": openid,  # 第三方平台的唯一标识
         "auth_token": ""  # 第三方平台的授权码
     }
     headers = {
         "Cache - Control": "no - cache",
         "Content - Type": "text / html;charset = UTF - 8",
         'Accept': 'application/json',
         "Date": "%s" % GetCurrentTime().getHeaderTime(),
         "Proxy - Connection": "Keep - alive",
         "Server": "nginx / 1.9.3(Ubuntu)",
         "Transfer - Encoding": "chunked"
     }
     third_login_url = "http://%s/user/thirdlogin" % ConfigFile().host()
     request = requests.post(third_login_url,
                             data=post_data,
                             headers=headers)
     time = GetCurrentTime().getCurrentTime()
     status_code = request.status_code
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
     finally:
         log_list = [
             u'QQ登录', u"post", third_login_url,
             str(post_data), time, status_code, info
         ]
         GetReport().get_report()  # 生成或打开日志文件
         GetReport().record_into_report(log_list)  # 逐条写入日志
Esempio n. 6
0
 def add_role(self, login, game_id, name):
     """
     添加游戏角色
     :param login:登录
     :param game_id: 游戏编号
     :return:
     """
     post_data = {
         "gameId": "%d" % game_id,
         "gamePlayer":
         "%s" % name,  #% ConfigFile().game_role_name(game_id),
         "gameServiceId": '146'
     }  #"%s" %  GameRegion().game_region(game_id)["data"][0]["id"]}
     headers = {
         "Cache - Control": "no - cache",
         "Content - Type": "text / html;charset = UTF - 8",
         'Accept': 'application/json',
         'Authorization': login["data"]["auth_token"],
         "Date": "%s" % GetTime().getHeaderTime(),
         "Proxy - Connection": "Keep - alive",
         "Server": "nginx / 1.9.3(Ubuntu)",
         "Transfer - Encoding": "chunked"
     }
     add_role_url = "http://%s/usergames/addRole" % ConfigFile().host()
     request = requests.post(add_role_url, data=post_data, headers=headers)
     time = GetTime().getCurrentTime()
     status_code = request.status_code
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
     finally:
         log_list = [
             u'添加游戏角色', u"post", add_role_url,
             str(post_data), time, status_code, info
         ]  # 单条日志记录
Esempio n. 7
0
 def delete_role(self, login, role_id):
     """
     删除角色
     :param login:
     :return:
     """
     post_data = {"roleId": "%d" % role_id}
     headers = {
         "Cache - Control": "no - cache",
         "Content - Type": "text / html;charset = UTF - 8",
         'Accept': 'application/json',
         'Authorization': login["data"]["auth_token"],
         "Date": "%s" % GetCurrentTime().getHeaderTime(),
         "Proxy - Connection": "Keep - alive",
         "Server": "nginx / 1.9.3(Ubuntu)",
         "Transfer - Encoding": "chunked"
     }
     delete_role_url = "http://%s/usergmaes/deleteRole" % ConfigFile().host(
     )
     request = requests.delete(delete_role_url,
                               data=post_data,
                               headers=headers)
     time = GetCurrentTime().getCurrentTime()
     status_code = request.status_code
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
     finally:
         log_list = [
             u'删除角色', u"delete", delete_role_url,
             str(post_data), time, status_code, info
         ]  # 单条日志记录
         GetReport().get_report()  # 生成或打开日志文件
         GetReport().record_into_report(log_list)  # 逐条写入日志
Esempio n. 8
0
 def match_status(self):
     """
     获取比赛状态
     :param token:
     :param match_id:
     :return:
     """
     post_data = {}
     headers = {
         "Cache - Control": "no - cache",
         "Content - Type": "text / html;charset = UTF - 8",
         'Accept': 'application/json',
         'Authorization': self.judgement_token,
         "Date": "%s" % GetTime().getHeaderTime(),
         "Proxy - Connection": "Keep - alive",
         "Server": "nginx / 1.9.3(Ubuntu)",
         "Transfer - Encoding": "chunked"
     }
     match_status_url = "http://%s/activity/%d/checkuseractstatus" % (
         ConfigFile().host(), self.match_id)
     request = requests.get(match_status_url,
                            data=post_data,
                            headers=headers)
     time = GetTime().getCurrentTime()
     status_code = request.status_code
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
     finally:
         log_list = [
             u'获取比赛状态', u"get", match_status_url,
             str(post_data), time, status_code, info
         ]  # 单条日志记录
Esempio n. 9
0
 def lose(self, token, id, screenings):
     post_data = {"screenings": "%d" % screenings}
     headers = {"Cache - Control": "no - cache",
                 "Content - Type": "text / html;charset = UTF - 8",
                 'Accept': 'application/json',
                 'Authorization': token,
                 "Date": "%s" % GetCurrentTime().getHeaderTime(),
                 "Proxy - Connection": "Keep - alive",
                 "Server": "nginx / 1.9.3(Ubuntu)",
                 "Transfer - Encoding": "chunked"}
     lose_url = "http://%s/activity/%d/transport" % (ConfigFile().host(), id)
     request = requests.post(lose_url, post_data, headers=headers)
     time = GetCurrentTime().getCurrentTime()
     status_code = request.status_code
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
             print(info)
     finally:
         log_list = [u'提交结果为负', u"post", lose_url, str(post_data), time, status_code, info]  # 单条日志记录
Esempio n. 10
0
 def sheet(self):
     workbook = xlrd.open_workbook(r"%s" %
                                   ConfigFile().users_path())  # 打开文件
     sheet = workbook.sheet_by_name(r"test_users")  # 根据索引获取工作表
     # print sheet.name, sheet.nrows, sheet.ncols  # 打印工作表名称、行数、列数
     return sheet
Esempio n. 11
0
        try:
            if status_code in (200, 422):
                json = request.json()
                info = json["info"]
                return json
            else:
                info = request.reason
                print(info)
        finally:
            log_list = [u'提交结果为负', u"post", lose_url, str(post_data), time, status_code, info]  # 单条日志记录
            # GetReport().get_report()  # 生成或打开日志文件
            # GetReport().record_into_report(log_list)  # 逐条写入日志


if __name__ == '__main__':
        id = 63  # 赛事ID4
        screenings = 1  # 轮次
        pool = mul_t.Pool(processes=100)
        result = []
        for token in ConfigFile().get_token():
            result.append(pool.apply_async(func=Result().win, args=(token, id, screenings)))
        # for token in ConfigFile().get_token():
        #     result_num = random.choice((1, 2))
        #     if result_num == 1:
        #         result.append(pool.apply_async(func=Result().win, args=(token, id, screenings)))
        #     elif result_num == 2:
        #         result.append(pool.apply_async(func=Result().lose, args=(token, id, screenings)))
        for r in result:
            print(r.get())

Esempio n. 12
0
 def __init__(self, judgement_token):
     self.judgement_token = judgement_token
     self.match_id = ConfigFile().activity_id()
Esempio n. 13
0
 def __init__(self, judgement_token):
     self.config_file = ConfigFile()
     self.judgement_token = judgement_token
     self.game_id = self.config_file.game_id()
Esempio n. 14
0
class CreateMatch:
    """
    创建比赛
    """
    def __init__(self, judgement_token):
        self.config_file = ConfigFile()
        self.judgement_token = judgement_token
        self.game_id = self.config_file.game_id()

    def create_match(self, post_data):
        headers = {
            "Cache - Control": "no-cache",
            "Content - Type": "application/json;charset = UTF - 8",
            'Accept': 'application/json',
            'Authorization': self.judgement_token,
            "Date": "%s" % GetTime().getHeaderTime(),
            "Proxy-Connection": "Keep - alive",
            "Server": "nginx / 1.9.3(Ubuntu)",
            "Transfer - Encoding": "chunked"
        }
        create_match_url = "http://%s/activity" % self.config_file.host()
        request = requests.post(create_match_url,
                                json=post_data,
                                headers=headers)
        time = GetTime().getCurrentTime()
        status_code = request.status_code
        try:
            if status_code in (200, 422):
                json_ = request.json()
                info = json_["info"]
                return json_
            else:
                info = request.reason
        finally:
            log_list = [
                u'发布比赛', u"post", create_match_url,
                str(post_data), time, status_code, info
            ]  # 单条日志记录
            # GetReport().get_report()  # 生成或打开日志文件
            # GetReport().record_into_report(log_list)  # 逐条写入日志

    def post_data(self, model, password=None):
        type = random.choice(MatchType().match_type(
            self.judgement_token, self.game_id)["data"])["id"]
        rule = random.choice(MatchRule().match_rule(
            self.judgement_token, self.game_id)["data"])["id"]
        people_data = random.choice(MatchPeople().match_people(
            self.judgement_token, self.game_id)["data"])
        people_id = people_data["id"]
        people_num = people_data["count"]
        # print(type(people_num))
        time_rule = GetTime().rule_time(int(people_num))
        if self.game_id == 1:
            game = "炉石"
        elif self.game_id == 2:
            game = "英雄"
        else:
            game = "守望"
        if model == "common":
            model_name = "常规"
            frozen = self.config_file.frozen()
            reward = self.config_file.raward(people_num, frozen)
            post_data02 = {
                "frozen": frozen,  # int,总蟠桃数
                "common_rewardrule": reward
            }  # Array,奖金规则,数组的键一定不能变(1,2,3,4,8,16)
        else:
            model_name = "奖池"
            entry_fee = self.config_file.entry_fee()
            reward = self.config_file.raward(people_num)
            post_data02 = {
                "apply_money": entry_fee,  # Int,报名费用.
                "money_rewardrule": reward
            }  # Array,奖金规则.eg:{"1":50}
        match_time = GetTime().match_time()
        title = game + model_name + match_time
        print(title)
        remark = random.choice(("""战城南,死郭北,野死不葬乌可食。\n
                                为我谓乌:“且为客豪,野死谅不葬,
                                腐肉安能去子逃?”\n
                                水深激激,蒲苇冥冥。\n
                                枭骑战斗死,驽马独徘徊。\n
                                梁筑室,何以南,何以北,\n
                                禾黍不获君何食?\n
                                愿为忠臣安可得?\n
                                思子良臣,良臣诚可思:\n
                                臣朝行出攻,暮不夜归。""", """有所思,乃在大海南。\n
                                何用问遗君,双珠玳瑁簪,用玉绍缭之。\n
                                闻君有他心,拉杂摧烧之。\n
                                摧烧之,当风扬其灰。\n
                                从今以往,勿复相思!\n
                                相思与君绝,鸡鸣狗吠,\n
                                兄嫂当知之。\n
                                妃呼豨!\n
                                秋风肃肃晨风飔,东方须臾高知之。""", " "))
        post_data01 = {
            "gameId": self.game_id,  # Int,游戏的Id
            "activityType": type,  # String,类型的ID
            "title": title,  # String,赛事标题
            "activity_rule_id": rule,  # Int,赛事规则的ID
            "activity_people": people_id,  # Int,选择人数的ID
            "model": model,  # String,常规模式(common),奖金池模式(money)
            "timerule": time_rule,  # Array,时间规则(eg:["2017-03-02 00:00:00"])
            "password": password,  # Int,赛事的房间密码,非必填
            "remark": remark
        }  # String,比赛的介绍,非必填
        post_data = dict(post_data01, **post_data02)
        print(post_data)
        return post_data