async def release_today(self, **kwargs) -> None: """Send embed listing today release from specified BetaSeries account Parameters ----------- ctx: :class:`reverse.core._models.Context` """ ctx = kwargs['ctx'] settings = kwargs.get("data", None) data = await self.planning_today() episodes = data.get('days', []) embed = Embed(title="Sortie du jour", color=0xe80005, timestamp=datetime.datetime.today(), thumbnail=self.LOGO) if (len(episodes) > 0): for e in episodes[0]['events']: e = e['payload'] try: name = "{} {} — {}".format(e['show_title'], e['code'], e['title']) except: name = "Movie : {}".format(e['title']) value = "[Source]({})".format(e['resource_url']) embed.add_field(name=name, value=value, inline=False) else: embed.add_field( name="Aucune sortie", value= "N'oubliez pas d'ajouter de nouvelle séries sur Betaseries.", inline=False) embed.set_footer(text="".format("The Reverse")) await ctx.send(embed=embed) if (settings != None): next_call = utils.generate_next_call( days=int(settings.get('Day', 1)), hours=int(settings.get('Hour', 7)), minutes=int(settings.get('Minute', 0)), seconds=int(settings.get('Second', 0)), adding=settings.get('Adding', False)) await ctx.send( "BetaSeries next call for the loop : {} - Δ:{} ".format( next_call, utils.time_until(next_call))) await ctx.send("Last call Δ:{} ".format( (settings.get('Date', None) - utils.now()).total_seconds())) print("BetaSeries next call for the loop : {} - Δ:{} ".format( next_call, utils.time_until(next_call))) self.task.recalculate_interval('release_today', next_call)
async def debugNextCall(self, ctx, *args): """Generate 10 datetime from generate_next_call, by default, addition is off, day = 1""" _kwargs, _args = utils.parse_args(args) _t = utils.now() _adding = "adding" in _args await ctx.send("0: {}".format(_t)) for i in range(1, 10): _tminus = _t _t = utils.generate_next_call(startDate=_t, days=int(_kwargs.get('day', 1)), hours=int(_kwargs.get('hour', 0)), minutes=int(_kwargs.get('minute', 0)), seconds=int(_kwargs.get('second', 0)), adding=_adding) await ctx.send("{}: {} - {}s".format( i, _t, utils.time_until(_t, startDate=_tminus)))
async def betastart(self, ctx, *args): """Create task that trigger worker at definied date Parameters ---------- ctx : :class:`reverse.core._models.Context` Context """ ctx = Context(ctx) _kwargs, _args = utils.parse_args(args) DEFAULT_CALL = self.release_today # Coroutine next call Datetime adding = "adding" in _args or False print(adding) next_call = utils.generate_next_call( days=int(_kwargs.get('day', 1)), hours=int(_kwargs.get('hour', 7)), minutes=int(_kwargs.get('minute', 0)), seconds=int(_kwargs.get('second', 0)), adding=adding) print(next_call) # Get delta from now until next_call delta = utils.time_until(next_call) data = { "Day": _kwargs.get('day', 1), "Hour": _kwargs.get('hour', 7), "Minute": _kwargs.get('minute', 0), "Second": _kwargs.get('second', 0), "Adding": _kwargs.get("adding", adding), "Timer": delta, "Date": next_call } # Store method.__name__ _task = _kwargs.get("task", DEFAULT_CALL.__name__) # Check if task is registered if (not any(e.__name__ == _task for e in self.worker)): await ctx.send("This worker is not compatible.") return try: # Test method callable(getattr(Series, _task)) # Try to find if task already running if ((_loop := self.task.findTaskByName(_task)) != None): _loop.stop() self.task.remove(_loop) await ctx.send("Overwrite betaseries task.") # Store method _task = getattr(self, _task) # Create loop with TaskService _loop = self.task.createLoop(_task, seconds=delta, ctx=ctx, data=data) # Start task self.task.start(_loop, load=_task, ctx=_loop.ctx, data=_loop.data) print("Betaseries task started. Delta : {} - Date : {}".format( delta, next_call))
def recalculate_interval(self, loop: str, when: datetime): delta = utils.time_until(when) loop = self.findTaskByName(loop) if (loop): loop.change_interval(seconds=int(delta))
def sleep_until(self, when, func): delta = utils.time_until(when) return self.createLoop(func, seconds=delta)