This commit is contained in:
bakatrouble 2019-01-28 01:07:57 +03:00
parent dac3e21a00
commit 459de8c00c
2 changed files with 6 additions and 4 deletions

View File

@ -13,14 +13,14 @@ from aggregator.models import AggregationSource, Message, Chat
Session.notice_displayed = True Session.notice_displayed = True
def get_client(): def get_client(takeout=False):
config._reload_maybe() config._reload_maybe()
if not config.pyrogram_session or not config.pyrogram_app_id or not config.pyrogram_app_hash: if not config.pyrogram_session or not config.pyrogram_app_id or not config.pyrogram_app_hash:
raise RuntimeError('Pyrogram is not configured') raise RuntimeError('Pyrogram is not configured')
session_path = os.path.relpath(default_storage.path(config.pyrogram_session.replace('.session', ''))) session_path = os.path.relpath(default_storage.path(config.pyrogram_session.replace('.session', '')))
return Client(session_path, config.pyrogram_app_id, config.pyrogram_app_hash) return Client(session_path, config.pyrogram_app_id, config.pyrogram_app_hash, takeout=takeout)
def save_message(client, message: PyrogramMessage): def save_message(client, message: PyrogramMessage):

View File

@ -11,5 +11,7 @@ def collect_new_messages(chat_id):
from .models import Chat from .models import Chat
chat = Chat.objects.get(pk=chat_id) chat = Chat.objects.get(pk=chat_id)
with get_client() as client: client = get_client(takeout=True)
_collect_new_messages(client, chat) client.start()
_collect_new_messages(client, chat)
client.stop()