Пример #1
0
 def create(action, **kwargs):
     action_name = action[0]
     if action_name == 'ataque_desarmado':
         return ActionFactory._create_unarmed_attack(kwargs)
     elif action_name == 'sleep':
         r_acao = Sleep()
         r_acao.ator = actor
         return r_acao
     raise AttributeError('Invalid action name')
Пример #2
0
    def add_sleep(self, start_minute, wake_minute):
        sleep = Sleep(start_minute, wake_minute)
        self.total_sleep_time += sleep.get_duration()
        self.sleeps.append(sleep)

        for minute in range(start_minute, wake_minute):
            if minute in self.minute_frequency:
                self.minute_frequency[minute] += 1
            else:
                self.minute_frequency[minute] = 1

            if self.minute_frequency[minute] > self.most_frequent_count:
                self.most_frequent_count = self.minute_frequency[minute]
                self.most_frequent_minute = minute
Пример #3
0
def main():
    tornado.options.parse_command_line()
    application = tornado.web.Application(
        # Routes
        [(r"/", MainHandler), (r"/getSleepValue", GetSleepValue),
         (r"/updateSleepValue", UpdateSleepValue), (r".*", ErrorHandler)],

        # Settings
        template_path=os.path.join(os.path.dirname(__file__), "templates"),
        static_path=os.path.join(os.path.dirname(__file__), "static"),
        debug=options.debug)
    main_loop = tornado.ioloop.IOLoop.instance()

    # Setting upp Sleep class
    application.sleepTicker = Sleep(options.audio, options.secondsLeft,
                                    options.startUpAudioVolume)

    #Adding callback for Sleep Class
    sleepLoop = tornado.ioloop.PeriodicCallback(application.sleepTicker.ticker,
                                                1000,
                                                io_loop=main_loop)
    sleepLoop.start()

    logging.info("Sleeper is started")

    try:
        application.listen(options.port)
        main_loop.start()
    except KeyboardInterrupt:
        logging.info("Good bye")
    except:
        logging.error("Could not start application!")
        exit()
Пример #4
0
def should_have_executed(monkeypatch) -> None:
    def mock_execute_cmd(*args: tuple, **kwargs: dict) -> str:
        assert args[0] == ['pmset', 'sleepnow']
        return 'Sleeping now...\n'
    monkeypatch.setattr(f"{MODULE_NAME}.execute_cmd", mock_execute_cmd)
    mute_logs(MODULE_NAME, monkeypatch)
    assert Sleep().execute() == 'Sleeping now...'
Пример #5
0
    async def run(self, duration, count: int = 2, **inputs):
        # spawn a bunch of tasks using a list comprehension:
        tasks = [Sleep(duration=duration) for _ in range(0, count)]

        # join() waits for a list of tasks to finish
        # it returns their results as a list:
        print('waiting for children to finish...')
        results = await join(tasks)

        print('all done')
        return results
Пример #6
0
 def execute(self) -> str:
     log('Good night!')
     automations = [
         Volume(['0.0']),
         Bluetooth(['off']),
         Wifi(['off']),
         Sleep(),
     ]
     for automation in automations:
         automation.execute()
     return ''
Пример #7
0
from hall_of_fame import HallOfFame

bot = Bot(command_prefix='$')


@bot.listen()
async def on_ready():
    for guild in bot.guilds:
        print(f'Guild: {guild.name}, {guild.id}')


if __name__ == '__main__':
    bot.remove_command('help')
    bot.add_cog(Help(bot))
    bot.add_cog(Hello(bot))
    bot.add_cog(Covid(bot))
    bot.add_cog(X(bot))
    bot.add_cog(Dice(bot))
    bot.add_cog(Landmine(bot))
    bot.add_cog(Sleep(bot))
    bot.add_cog(Tex(bot))
    bot.add_cog(Mine(bot))
    bot.add_cog((MessagePlayback(bot)))
    bot.add_cog(Doctor(bot))
    bot.add_cog(HallOfFame(bot))
    # bot.add_cog(Cropped(bot))

    TOKEN = os.environ['DISCORD_BOT_TOKEN']
    # sleepCommand = sleep.Sleep()
    bot.run(TOKEN)
Пример #8
0
    def __init__(self, url):

        self.request = Request(url)

        self.arguments = Arguments()
        self.sleep = Sleep()
Пример #9
0
class RequestProcess:
    def __init__(self, url):

        self.request = Request(url)

        self.arguments = Arguments()
        self.sleep = Sleep()

    def get(self, headers=None, timeout=None):

        if not headers:
            headers = self.format_request_headers()

        response = self.request.get(headers, timeout)

        if response.status_code == 429:

            if self.is_wait_limit(response):

                return self.get(headers, timeout)

        if response.status_code == 403:

            self.print_error_message(response)

            if self.is_github_ratelimit(response):

                return self.get(headers, timeout)

        return response

    def format_request_headers(self):

        headers = {}
        github_token = self.arguments.get_github_token()

        if github_token:
            headers['Authorization'] = f'token {github_token}'

        return headers

    def is_wait_limit(self, response):

        sleep_time = None

        if 'Retry-After' in response.headers:

            sleep_time = int(response.headers['Retry-After'])

        self.sleep.start(sleep_time)

        return False

    def is_github_ratelimit(self, response):

        if 'X-RateLimit-Remaining' in response.headers:

            limit_remaining = int(response.headers['X-RateLimit-Remaining'])

            if limit_remaining == 0 and 'X-RateLimit-Reset' in response.headers:

                reset_time = int(response.headers['X-RateLimit-Reset'])
                current_time = int(time.time())
                sleep_time = reset_time - current_time + 1

                return self.sleep.start(sleep_time)

        return False

    def print_error_message(self, response):

        error_resopnse = response.json()

        if 'message' in error_response:

            print(error_resopnse['message'])
Пример #10
0
    def __init__(self, user, query):

        self.url = self.format_url(user, query)
        self.sleep = Sleep()
Пример #11
0
def should_have_printed_usage_instructions(monkeypatch) -> None:
    print_coloured_calls = []
    monkeypatch.setattr(f"{MODULE_NAME}.print_coloured", lambda *a, **k: print_coloured_calls.append(''))
    Sleep().usage()
    assert len(print_coloured_calls) == 2