Exemple #1
0
from pyrogram import Client
from config import api_id, api_hash
from pyrogram.errors import FloodWait
import time

app = Client(
    "my_account",
    api_id=api_id,
    api_hash=api_hash
)

app.start()

print("Количество сообщений:")
for dialog in app.iter_dialogs():
    try:
        count_messages = app.get_history_count(dialog.chat.id)
    except FloodWait as e:
        print("Перекур, телега не вечная...")
        print("Ждём {} секунд....".format(e.x))
        time.sleep(e.x)
    if dialog.chat.title:
        print("{} - {}".format(dialog.chat.title, count_messages))
    else:
        print("{} - {}".format(dialog.chat.username, count_messages))
from flask import Flask
from pyrogram import Client
import asyncio
from threading import Thread

api_id = 1234
api_hash = "123123123213abaabba"
chat_id = "@durov"

app = Client(session_name="markov", api_id=api_id, api_hash=api_hash)
flaskapp = Flask(__name__)

f = open("current_msg.txt", "r")
if not f:
    current_id = app.get_history_count(chat_id)
else:
    current_id = int(f.read())
global messages
i = 100


async def read_msg():
    global messages
    global i
    global current_id

    if i == 100:
        messages = app.get_history(chat_id=chat_id,
                                   offset_id=current_id,
                                   limit=100)
        print("GOT NEW HISTORY")