0

I have a simple script for telegram reposting, which sleeps until its 2:00, after reposting 3 messages from a channel to another one.

channelvar = 0
@client.on(events.NewMessage(chats=(INPUT_CHANNEL)))
async def normal_handler(event):
    global channelvar
    await client.send_message(OUTPUT_CHANNEL, event.message)
    channelvar = channelvar + 1
    if channelvar >= 3:
        for i in range(0,365):
            t = datetime.datetime.today()
            future = datetime.datetime(t.year,t.month,t.day,2,0)
            if t.hour >= 2:
                future += datetime.timedelta(days=1)
                channelvar = 0
                time.sleep((future-t).total_seconds())

I need it to be stopped when the condition (3 messages per day) was met in one day and restart the loop every morning. For example, how it works now:

  1. I get 1 post on day(1), channelvar = 1.
  2. Then I get 2 posts on the next day, channelvar = 3. The loop sleeps until it's 02:00.

How can I make it work when 3 posts were published on one day?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • Is it possible to schedule this from cron or somewhere else instead? Here are some ideas: https://stackoverflow.com/q/373335/245915 – nofinator Oct 03 '22 at 16:58

0 Answers0