Exemple #1
0
class RunTanxian(SaoDangFb,Tanxian):
    def __init__(self,*args):
        super(RunTanxian, self).__init__(*args)
        self.logger = MyLog(logname="tanxian.log")
    def run(self):
        index  =self.index()
        explore_now = index['explore_now']
        for item in explore_now:
            if int(item['explore_status'])==2:
                id = item['area_id']
                self.explore_receive_reward(id)
                self.one_button_join(id)
                self.explore_start(id)
                return True
            elif int(item['explore_status'])==3:
                self.logger.info('您还在探索中!')
                return True
        area_now = index['area_now']
        area_now = sorted(area_now,key=lambda x:x['area_level'])
        id = area_now[0]['area_id']
        self.p(id)
        self.area_reward_into(id)
        self.explore_receive_reward(id)
        self.one_button_join(id)
        self.explore_start(id)
Exemple #2
0
class OverseaStrade(SaoDangFb):
    reward_type = {
        '2': '银币',
        '4': '紫',
        '7': '声望',
        '33': '战功',
    }

    def __init__(self, *args):
        super(OverseaStrade, self).__init__(*args)
        self.log = MyLog(logname='oversea.log')

    def index(self):
        index = self.action(c='overseastrade', m='index')
        return index

    def world_index(self):
        index = self.action(c='overseastrade', m='world_index')
        print index
        if index['status'] != 1:
            self.log.error('world_index status not :%s' % index)
            time.sleep(0.5)
            index = self.action(c='overseastrade', m='world_index')
        self.log.info('world_index result %s' % index)
        return index

    def world_refresh(self, page):
        formdata = {
            "page": page,
        }
        world_refresh = self.action(c='overseastrade',
                                    m='world_refresh',
                                    body=formdata)
        return world_refresh

    def ship_list(self):
        #商船选择
        ship_list = self.action(c='overseastrade', m='ship_list')
        self.log.info('ship_list status:%s' % ship_list)
        return ship_list

    def renovate_ship(self):
        #刷新商船
        ship_list = self.ship_list()
        price = int(ship_list['price'])
        renovate_ship = ''
        while price == 0:
            renovate_ship = self.action(c='overseastrade', m='renovate_ship')
            try:
                price = int(renovate_ship['price'])
            except:
                break
        return renovate_ship

    def renovate_world_goods(self):
        #刷新商品
        """
        :return:
        """
        self.log.info('renovate_world_goods')
        num = 0
        while num < 5:
            result = self.action(c='overseastrade',
                                 m=self.get__function_name())
            if result['status'] == 1:
                return result
            elif result['status'] == 11:
                num += 1
                time.sleep(0.5)
        return ""

    def world_goods_list(self):
        self.log.info(self.get__function_name())
        result = self.action(c='overseastrade', m=self.get__function_name())
        self.log.info("%s:%s" % (self.get__function_name(), result))
        return result

    def harbour_list(self):
        result = self.action(c='overseastrade', m=self.get__function_name())
        self.log.info("%s:%s" % (self.get__function_name(), result))
        return result

    def get_list_from_world(self, page=1):
        formdata = {"page": page}
        result = self.action(c='overseastrade',
                             m=self.get__function_name(),
                             body=formdata)
        self.log.info("%s:%s" % (self.get__function_name(), result))
        return result

    def quit(self):
        #退出
        result = self.action(c='overseastrade', m=self.get__function_name())
        self.log.info("%s:%s" % (self.get__function_name(), result))
        return result

    def choose_harbour(self, harbour_id=2):
        #选择港口 1 银币 2 紫 3 声望 4战功
        #默认ID 2 为紫石头加成
        self.harbour_list()
        formdata = {"harbour_id": harbour_id}
        result = self.action(c='overseastrade',
                             m=self.get__function_name(),
                             body=formdata)
        self.log.info("%s:%s" % (self.get__function_name(), result))
        return result

    def choose_world_goods(self, goods_id=6):
        #选择商品 1
        #默认ID 6 为镔铁长刀
        print 'choose_world_goods_id{goods_id}'.format(goods_id=goods_id)
        formdata = {"goods_id": goods_id}
        result = self.action(c='overseastrade',
                             m=self.get__function_name(),
                             body=formdata)
        self.log.info("%s:%s" % (self.get__function_name(), result))
        self.choose_harbour()
        return result

    def join_world_team(self, site, place, page, id=0):
        #加入团队id 为0,创建队伍
        self.harbour_list()
        formdata = {
            "id": id,
            "site": site,
            "place": place,
            "page": page,
        }
        result = self.action(c='overseastrade',
                             m=self.get__function_name(),
                             body=formdata)
        self.log.info("%s:%s" % (self.get__function_name(), result))
        return result

    def world_start(self):
        #开始
        print '开始跑船'
        result = self.action(c='overseastrade', m=self.get__function_name())
        if result['status'] != 1:

            self.log.error('world_start error %s' % result['msg'])
            for item in self.world_goods_list()['list']:
                if int(item['status']) == 1:
                    self.choose_harbour(item['harbour'])
            result = self.action(c='overseastrade',
                                 m=self.get__function_name())
        self.log.info("%s:%s" % (self.get__function_name(), result))
        return result

    def run(self):
        self.world_goods_list()
Exemple #3
0
class JadeTower(SaoDangFb):
    def __init__(self, *args):
        super(JadeTower, self).__init__(*args)
        self.log = MyLog(logname="JadeTower")

    def index(self):
        index = self.action(c='jade_tower', m='index')
        return index

    def start(self):
        start = self.action(c='jade_tower', m='start')
        return start

    def create_room(self,
                    name=111,
                    limit_type=0,
                    floor=2,
                    min_level=0,
                    password=""):
        formdata = {
            "name": name,
            "limit_type": limit_type,
            "floor": floor,
            "min_level": min_level,
            "password": password,
        }
        status = self.action(c='jade_tower', m='create_room', body=formdata)
        return status

    def fight(self):
        while True:
            index = self.index()
            if int(index['monster_number']) <= 0:
                break
            self.log.info("figth_index:%s" % index)
            fight = self.action(c='jade_tower', m='fight')
            self.log.info("fight:%s" % fight)
            time.sleep(0.5)

    def fight_refine(self, id=30):
        #默认是炼化南明离火剑30
        #炼化
        index = self.index()
        formdata = {"refine_id": id}
        if index['phase'] == 3 and index['refine_info']:
            while True:
                index = self.index()
                self.log.info('fight_refine_index:%s' % index)
                if int(index['refine_info']['times']) == 0:
                    self.log.info('fight_refine:炼化结束')
                    break

                fight_refine = self.action(c='jade_tower',
                                           m='fight_refine',
                                           body=formdata)
                self.log.info('fight_refine:%s' % fight_refine)
                time.sleep(1)
        else:
            self.log.error('fight_refine:还没有到炼化步骤')

    def run(self, floor):
        index = self.index()
        if index['join_room']:
            join_room = index['join_room']
            if int(join_room['member2_ready']) == 1 and int(
                    join_room['member1_ready']) == 1:
                #所有人员都准备
                self.start()
                self.fight()
                self.fight_refine()
        else:
            status = self.create_room(floor=floor)
            self.log.info('create_room:%s' % (status))
            return
        self.fight_refine()
Exemple #4
0
class MainPage(BasePage):
    _quit_locator = (By.XPATH, '//*[@id="_mail_component_120_120"]/a')  # 退出邮箱
    _maillist_locator = (By.XPATH, '//*[@id="_mail_tabitem_1_117text"]')  # 通讯录
    _inbox_locator = (By.XPATH, '//*[@id="_mail_tabitem_3_119text"]')  # 收件箱
    _sendmail_locator = (By.XPATH, '//span[text()="写 信"]')  # 写邮件按钮
    _close_label_locator = (By.XPATH, '//a[@title="点击关闭标签"]')

    def __init__(self):
        self._path = os.path.abspath(os.path.dirname(
            os.path.dirname(__file__))) + '\\data\\cookie'
        self.logger = MyLog().mylogger()
        self.open_browser()

    @allure.step('打开浏览器')
    def open_browser(self):
        self.logger.info('\n' + '*' * 20 + '打开浏览器' + '*' * 20 + '\n')
        self.driver = Browser().open_browser()

    # 点击关闭标签
    @allure.step('点击关闭标签')
    def click_close_label(self):
        self.logger.info('点击关闭标签')
        self.find_and_click(self._close_label_locator)
        return self

    # cookie写入文件
    @allure.step('cookie写入文件')
    def write_cookie_to_txt(self):
        try:
            self.logger.info('获取cookie')
            dict_cookies = self.driver.get_cookies()
            self.logger.info('将获取的cookie序列化')
            json_cookies = json.dumps(dict_cookies)
            print(json_cookies)
            with open(self._path, 'w') as f:
                self.logger.info('cookie写入文件')
                f.write(json_cookies)
        except Exception as e:
            self.logger.info(e)

    # 从文件中读cookie
    @allure.step('从文件中读cookie')
    def read_cookie_txt(self):
        try:
            with open(self._path, 'r', encoding='utf8') as f:
                self.logger.info('从文件中读cookie')
                list_cookies = json.loads(f.read())
            return list_cookies
        except Exception as e:
            self.logger.info(e)

    # 通过cookie登录
    @allure.step('通过cookie登录')
    def login_by_cookie(self):
        self.logger.info('通过cookie登录')
        list_cookies = self.read_cookie_txt()
        for cookie in list_cookies:
            if 'expiry' in cookie:
                del cookie['expiry']
            self.driver.add_cookie(cookie)
        time.sleep(2)
        self.logger.info('刷新浏览器')
        self.driver.refresh()
        return self

    @allure.step('去登录页')
    def login_no_cookie(self):
        self.logger.info('去登录页')
        return LoginPage(self.driver, self.logger)

    # 回到登录页
    @allure.step('回到登录页')
    def to_login(self):
        self.login_by_cookie()
        self.find_and_click(self._quit_locator)
        return LoginPage(self.logger)

    # 去通讯录页面
    @allure.step('去通讯录页面')
    def to_maillist(self):
        self.login_by_cookie()
        self.logger.info('点击通讯录页面')
        self.find_and_click(self._maillist_locator)
        return MailListPage(self.driver, self.logger)

    # 去收件箱页面
    @allure.step('去收件箱页面')
    def to_inbox(self):
        self.login_by_cookie()
        self.logger.info('点击收件箱页面')
        self.find_and_click(self._inbox_locator)
        return InBoxPage(self.driver, self.logger)

    # 去写邮件
    @allure.step('去写邮件')
    def to_sendmailpage(self):
        self.login_by_cookie()
        self.logger.info('关闭广告标签')
        self.click_close_label()
        self.logger.info('点击去写邮件')
        self.find_and_click(self._sendmail_locator)
        return SendMailPage(self.driver, self.logger)