Beispiel #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)
Beispiel #2
0
    def run(self, r, job, job_id):
        job.add_job(self.a,
                    'interval',
                    seconds=1,
                    id=job_id,
                    args=(r, job, job_id))


#实例化redis 实例对象
pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
r = redis.StrictRedis(connection_pool=pool)

s1 = threading.Semaphore(10)
l = threading.Lock()
log = MyLog(logpath='banquet', logname='banquet.log')
schdeuler = schdeuler(log)


def act(user, apass, addr, job, job_id, r):
    s1.acquire()
    action = banquet(user, apass, addr)
    action.run(r, job, job_id)
    s1.release()


filepath = os.path.dirname(os.path.abspath(__file__))
cont = ['banquetuser.txt']
# cont = ['qingbing.txt']
for t in cont:
    with open('%s/users/%s' % (filepath, t), 'r') as f:
Beispiel #3
0
            crontime = resutl['user_info']['time_poll']
        except:
            return 86000

        print self.user, '剩余%s秒' % (crontime)
        return crontime

    def poll_reward(self):
        self.action(c='quyuan_festival', m='poll_index')
        self.action(c='quyuan_festival', m='poll_reward')
        self.action(c='quyuan_festival', m='take_poll')


s1 = threading.Semaphore(20)
l = threading.Lock()
log = MyLog(logpath='quyuan', logname='quyuan.log')

if __name__ == '__main__':
    s1 = threading.Semaphore(5)
    scheduler = BlockingScheduler()
    executors = {
        'default': {'type': 'threadpool', 'max_workers': 20},
        'processpool': ProcessPoolExecutor(max_workers=5)
    }
    job_defaults = {
        'coalesce': False,
        'max_instances': 50,
        'misfire_grace_time': 100,
    }
    scheduler.configure(executors=executors, job_defaults=job_defaults)
Beispiel #4
0
            #移除原来的任务id
            print reward_right_cd
            job_id = self.user+self.num
            self.action(c='act_sword', m='get_rank_reward', type=1)
            self.action(c='act_sword', m='get_rank_reward', type=0)
            start = self.action(c='act_sword', m='start')
            if start['status'] == 1:
                if int(start['need_nums']) > reward_right_cd / 60:
                    return reward_right_cd / 60
                else:
                    return start['need_nums']

if __name__ == '__main__':
    s1 = threading.Semaphore(10)
    l = threading.Lock()
    log = MyLog(logpath='D:\hjsg\utils',logname='zhujian.log')
    schdeuler =schdeuler(log)
    def act(user, apass, addr,job,log):
        s1.acquire()
        action = zhujian(user, apass, addr)
        num = int(action.act_sword(job,log))
        job_id = user + addr
        #添加任务,循环调用act 函数,以便动态添加定时任务
        log.info(job.add_job(act,next_run_time=(datetime.datetime.now() + datetime.timedelta(minutes=num)),
                          args=(user,apass,addr,job,log),id=job_id))
        s1.release()
    filepath = os.path.dirname(os.path.abspath(__file__))
    cont = ['sunzi.txt']
    # cont = ['qingbing.txt']
    for t in cont:
        with open('%s/users/%s' % (filepath, t), 'r') as f:
Beispiel #5
0
 def __init__(self, *args):
     super(OverseaStrade, self).__init__(*args)
     self.log = MyLog(logname='oversea.log')
Beispiel #6
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()
Beispiel #7
0
def main(name, passwd, addr):
    log = MyLog(logname="country_shop")
    a = country_taxes_shop(log, name, passwd, addr)
    a.buy()
Beispiel #8
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/9/10 10:37
# @Author  : xingyue
# @File    : task.py

from task.base import SaoDangFb
from utils.mylog import MyLog

import threading
import os, time

logger = MyLog()

class CountryBoss(SaoDangFb):

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

    def powerup(self):
        logger.info('开始银币强化攻击')
        boss_info = self.index()
        try:
            powerup = int(boss_info['powerup'])
        except:
            self.p(boss_info)
        if powerup < 200:
            for i in range((200 - powerup) / 10):
                status= self.action(c='countryboss', m='powerup', gold=0)
                logger.info('powerup:%s'%status)
Beispiel #9
0
 def __init__(self, *args):
     super(JadeTower, self).__init__(*args)
     self.log = MyLog(logname="JadeTower")
Beispiel #10
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()
Beispiel #11
0
 def __init__(self):
     self._path = os.path.abspath(os.path.dirname(
         os.path.dirname(__file__))) + '\\data\\cookie'
     self.logger = MyLog().mylogger()
     self.open_browser()
Beispiel #12
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)
Beispiel #13
0
 def __init__(self,*args):
     super(RunTanxian, self).__init__(*args)
     self.logger = MyLog(logname="tanxian.log")