0

I know that the get_chat_history() method has a parameter "offset_date" but it gets all messages older than a particular date, and I need to get all messages that are "newer". Please help.

I've tried googleing the problem, but nothing has helped.

matveygal
  • 1
  • 2

1 Answers1

0

Save the output to a sqlite table and create a field to hold the date you want use as your start date Pass the current date.time as the offset date. Tell it to stop downloading when message dates match the date in your sqlite field.

It will start with current and download until it gets to your intended date.

async def fetch_messages(app, channel):
conn = sqlite3.connect('c:\sqlite3\your.db')
c = conn.cursor()


# Fetch the intended date from your db

try:
    offset_date = datetime.datetime.now()  # Get the current date as the offset
    async for message in app.get_chat_history(chat_id, offset_date=offset_date):
        # Break the loop if message date is older than dl_history
        if message.date.timestamp() < dl_history:
            break
Guest
  • 1