Ejemplo n.º 1
0
    def __init__(self, cj_filename, user_conf=None):
        """Initialize the automator.

        :param user_conf: filename for configuration
        :param cj_filename: filename for cookiejar
        :returns: None
        """

        Cf()
        if user_conf is not None:
            if not os.path.exists(user_conf):
                raise exc.FileNotFoundError("configuration file not found.")
            else:
                Cf.update(user_conf)

        if not os.path.exists(cj_filename):
            raise exc.FileNotFoundError("cookie-jar file not found.")

        self._parser = Parser()

        self._cj_file = cj_filename
        self._cj = cookiejar.LWPCookieJar()
        if os.path.isfile(self._cj_file):
            self._cj.load(self._cj_file)

        cookie_proc = urllib2.HTTPCookieProcessor(self._cj)
        self.opener = urllib2.build_opener(cookie_proc)

        self._header = {
            "Accept-Language": Cf.get('user.lang'),
            "Accept": Cf.get('user.mime'),
            "Accept-Charset": Cf.get('user.charset'),
            "User-Agent": Cf.get('user.ua'),
        }

        self.url_prefix = Cf.get('service.url_prefix')
        self.path_prefix = self.url_prefix + self.__get_prefix()
        Cf.set('service.path_prefix', self.path_prefix)
Ejemplo n.º 2
0
    def loop(self, display):
        init_info = self.get_info()
        display.show_info(init_info)

        sleep_base = int(Cf.get('automator.sleep_base'))
        sleep_rand = int(Cf.get('automator.sleep_rand'))
        interval = int(Cf.get('automator.interval'))
        iv_range = int(Cf.get('automator.interval_range'))
        time.sleep(sleep_base + random.randrange(sleep_rand))

        st_flag = True
        if Cf.get('automator.event_priority') == '0':
            # mission
            status = self.do_recent_mission()
            st_flag = status['info']['st_flag']
            display.show_mission_status(status, action='do_mission')
            time.sleep(sleep_base + random.randrange(sleep_rand))

            info = self.get_info()

            # battle
            if info['power_cur'] == info['power_max']:
                l.info("%sbattle%s" % (Color.YELLOW, Color.END_COLOR))
                self.battle()
                time.sleep(sleep_base + random.randrange(sleep_rand))
                after_info = self.get_info()
                gain = after_info['energy'] - info['energy']
                l.info(" - gain:%d" % gain)

                display.show_info(after_info)
                display.show_guild_info(self.get_guild_info())

            # investment
            time.sleep(sleep_base + random.randrange(sleep_rand))
            if info['energy'] > int(Cf.get('automator.investment_threshold')):
                l.info(' - investment 1k')
                self.get_investment1k()

            if not st_flag:
                interval_sec = interval + random.randrange(iv_range)
                time.sleep(interval_sec)
        else:
            l.warn('Not implemented: event_priority > 0')
            time.sleep(600)